Getting a single form result grouped by form page

11 views
Skip to first unread message

Anferney Grotestam

unread,
Oct 31, 2024, 9:57:55 AM10/31/24
to General WebHare developers discussion
I have a form which has two pages. Each page has 2 textfields.

I'm trying to group the values of a result by page with the code below.
The pages variable contains records, which contains a pagefields cell, which in return is an array of all the answers beloning to the field contained within the page.
However, when running the code below, all the pages contain all of the values of the result.

I'm i going about this the wrong way or is there an easier way to accomplish this?

OBJECT formobj := OpenWHFSObject(formid);

OBJECT formresults := OpenFormFileResults(formobj);

this->pdfdata := formresults->GetSingleResult(resultguid);

RECORD singleresult := this->pdfdata;

OBJECT formdef := OpenFormFileDefinition(formobj);

RECORD ARRAY wittyresults := formresults->GetWittyResultData(singleresult).allfields;

RECORD ARRAY pages;
FOR (INTEGER idx := 0; idx < formdef->GetNumPages(); idx := idx + 1)
{
OBJECT page := formdef->GetPage(idx);

RECORD ARRAY pagefields;

FOREVERY (RECORD result FROM wittyresults)
{
OBJECT component := page->LookupComponent(result.fieldguid);

IF (ObjectExists(component))
{
INSERT result INTO pagefields AT END;
}
}

INSERT cell [pagefields] INTO pages AT END;
}

Arnold Hendriks

unread,
Nov 1, 2024, 6:49:18 AM11/1/24
to General WebHare developers discussion, anfe...@nubium.nl
On Thursday, October 31, 2024 at 2:57:55 PM UTC+1 anfe...@nubium.nl wrote:
I have a form which has two pages. Each page has 2 textfields.

I'm trying to group the values of a result by page with the code below.
Why not look at 'pages' instead of 'allfields' then ? (use 'Test result' in the results context menu on an email handler to see the actual structure of the data)
 
The pages variable contains records, which contains a pagefields cell, which in return is an array of all the answers beloning to the field contained within the page.
However, when running the code below, all the pages contain all of the values of the result.

Yes - because some user want to show all fields in the result emails, even if the user did not fill or see them. The witty structure attempts to cover all these use cases.

This is the default templated used for results

[component resultstable]
<div class="defaultmail__results">
[forevery pages]
[forevery groups]
[if anysubmitted]
<div class="defaultmail__results__group">
[if title] [! group title !]
<h2 class="defaultmail__results__group__header">[title]</h2>
[/if]
[forevery fields]
[if issubmitted]
<div class="defaultmail__results__line">
<h3 class="defaultmail__results__fieldline__title">[title]</h3>
<div class="defaultmail__results__fieldline__value">
[if files]
[forevery files]
<a href="[link]">[text]</a><br> [! filename is just the name, text is 'goudvis.png (74 KB, image/png)' !]
[/forevery]
[elseif link]
<a href="[link]">[text]</a>
[else]
[text]
[/if]
</div>
</div>
[/if]
[/forevery]
</div>
[/if]
[/forevery]
[/forevery]
</div>
[/component]


Filter by 'issubmitted' to hide fields not seen by the user but still show fields left empty, and I'd say just filter on IsValueSet(text) if you only want to find actually filled values


Reply all
Reply to author
Forward
0 new messages