Is there a way to retrieve historical form submissions?

Vote:
 

I want to build a report that shows form submission data, but using the code below gives me nothing:

var formDataRepository = new FormDataRepository();
var formsInfo = _formRepository.Service.GetFormsInfo(null);

var membershipForm = formsInfo.Single(x => x.Name.Contains("<omitted>"));
var submittedData = formDataRepository.GetSubmissionData(new FormIdentity(membershipForm.FormGuid, string.Empty),
                                                                DateTime.Now.AddDays(-100), DateTime.Now).ToList();

From what I've read, this may just returned data for just submitted forms or something. Or maybe I read that wrong. Either way, is there a way to achieve this?

#286774
Sep 07, 2022 17:57
Vote:
 

Hi 

I don't see any issue with your code. The question is where your form is created. If your form is created and stored under "For this page" local folder, you'll have challenge to get form's identity. The GetFormsInfo only find the form in the root folder under "EPiServer Form".

#286817
Sep 08, 2022 2:36
eperezjr - Sep 08, 2022 14:42
The form is not in the page local folder. It's in a subfolder under _EpiServer Forms. Is that fine? And can my code be ran from anywhere? Or does it have to run in the form somehow?
Vote:
 

If you look into your database, FormData_xxxx (where xxx is your FormGuid), do you  see any data that matches your query?

Also you might want to use the injected IFormDataRepository. In this case new FormDataRepository() is fine, but it is a bad pattern we'd want to avoid

#286827
Sep 08, 2022 9:52
Vote:
 

Hi 

I have tested in CMS 12, it works for forms stored under "Episerver Forms" folder (see attached)

#287045
Sep 12, 2022 2:26
Paul McGann (Netcel) - Sep 30, 2022 12:18
In you screengrab you have var f = a.FirstOrDefault.... should that not be b.FirstOrDefault?

Also the formIdentity you are setting the language to null, while i think it should work have you tried 'new (FormIdentity(f.FormGuid))'?
Vote:
 

GetFormsInfo will get all forms recursively, so it does not have to be under the Forms root. As I said, check the data you have in your database 

#287121
Sep 13, 2022 9:53
Vincent - Sep 13, 2022 11:29
According to my test, It doesn’t seem returning the forms stored under “For this page”.
Quan Mai - Sep 13, 2022 12:40
Hmm, that's true. I meant it can be under a ContentFolder that is under the Forms root.
* 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.