|
Best of Support |
|
|
Iterating through fields in a Dialog |
|
Issue
Is there a way to iterate the fields in a GhostFill Dialog without knowing in advance the names of the fields? I'm trying to figure out a way to write a generic script that performs the same operations on the fields in a Dialog (handling unanswered variables, for example) without having to write a new script for each Dialog that contains hard coded references to the field names.
Solution:
Yes, you can iterate through all fields on a Dialog form, and get amongst other things their:
name
value
answered status
The following script illustrates how to do this. When reviewing this script, two things to bear in mind:
The field index count starts at zero.
There will be some 'system' fields (e.g., "_version" and "_mapping"), but these can be easily stripped out as their first character will always be an underscore.
Here is the sample script:
%[i=0]
%[RepeatBlockWhile(i<thisDialog.dynamicpropertycount)]
%[DeleteBlockIf( Left(thisDialog.dynamicpropertyname(i),1) ="_") |This removes system fields]
%[MsgBox( "Field Name:", thisDialog.dynamicpropertyname(i) )]
%[MsgBox( "Field Value:", thisDialog.dynamicpropertyvalue(i) )]
%[MsgBox( "Answered:",thisDialog.form.fields.getv(thisDialog.dynamicpropertyname(i)).answered)]
%[EndBlock()]
%[i=i+1]
%[Endblock()]
Daniel Todes