November Happy Hour will be moved to Thursday December 5th.

Accessing EPi Forms Data in Schedule Job

Vote:
 

Hi, 

Im creating a schedule job to achieve the following

  • Get all EPiserver Forms (prefixed with a specific value)
  • Loop through the submission data and check a particular form elements value
  • If the form element has the value i am looking for then i will 'do more work'

So far i am doing the following..

 //get all EPi forms
var forms = _formRepository.GetFormsInfo(string.Empty).Where(x => x.Name.StartsWith("XX_"));
foreach (var form in forms)
{
//unsure how to get language
var list = _formDataRepository.GetSubmissionData(new FormIdentity(form.FormGuid, "en-GB"), startDate, endDate);
}

During local testing I found that _formRepository.GetFormsInfo only returns forms that have not been created 'for this page'. How can i also include forms created for this page? Also,  _formRepository.GetFormsInfo returns IEnumerable so when looping through the FormInfo object only exposes the following

  • FormGuid
  • Id
  • Name 

However, when attempting to get the forms submission data it expects a FormIdentity which subsequently expects a language which i am not sure how to get dynamically? At the minute i hard coded it like so 

//unsure how to get language
var list = _formDataRepository.GetSubmissionData(new FormIdentity(form.FormGuid, "en-GB"), startDate, endDate);


As this is in a schedule task and not on a page I have no content reference where i can get at the language so how can i make that dynamic? 

Maybe the approach of getting all forms using the following and then looping through usages is a better approach? (https://world.episerver.com/forum/developer-forum/Developer-to-developer/Thread-Container/2016/1/get-all-blocks-by-block-type/)

var contentType = _contentTypeRepository.Load();

Can anyone point me in the right direction please?

Thanks

 

 

#195061
Edited, Jul 12, 2018 12:47
Vote:
 

If it's true that the GetFormsInfo() method does not include any forms referenced in the "On this page" local folder, this is probably a bug and makes it slightly more challenging, as you’re going to need to find a way to retrieve the form identity from the content reference, probably by querying the DDS directly. I would go with this approach:

  • Retrieve instances of the FormContainerBlocks using the ContentUsage repository, more specifically the ListContentOfContentType method. It's certainly fine to use in the scope of a scheduled job providing it's not executed multiple times a second (in which case even that's probably fine because of the concrete caching mechanisms).
  • Filter your results based on your naming convention and cast to an IContent reference. You can use the contentLink returned from the ContentUsage class to do this. Once you have a content reference, you can retrieve your language information etc.
  • Query the Dynamic Data Store to retrieve the form that has the associated contentLink and grab the form id from that query, which you can then pass into the GetFormsInfo() method.

 

Although I must say this feels like a slightly messy workaround for the GetFormsInfo() not retrieving instances of the forms situated in the “For this page” folders. It may be worth checking if this is a specific bug to the version of Episerver CMS that you’re developing with, and flag it to the support team to get it fixed. 

#195074
Jul 12, 2018 15:14
Vote:
 

Hi James, 

Thank you for your response. 

With regards to 'when attempting to get the forms submission data it expects a FormIdentity which subsequently expects a language which i am not sure how to get dynamically?'

This was as simple as passing string.Empty so my code is as follows:

//get form identity - passing an empty lang returns all forms versions
_formIdentity = new FormIdentity(form.FormGuid, string.Empty);

//get form submissions
var submissionsList = _formDataRepository.GetSubmissionData(_formIdentity, startDate, endDate);

However, the above still doesnt return forms 'for this page'

Thanks 

Paul

#195416
Edited, Jul 24, 2018 15:41
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.