Using template literals in Create Feature activity
I have a workflow in which a user selects as many line features as they need. Then each participating line segment gets a few of its own attributes (in a relationship table).
The corresponding form elements for these segment-specific attributes are dynamically generated for each feature selected, since the user may choose any number of features.
For example, I am having trouble to get this object to fully evaluate:
={
'RID':$objectIds1.ids[$forEachSelectedFeature2.pass],
'TimesJetted':($SegmentsForm.state.intTimesJetted`${$forEachSelectedFeature2.pass}`.value == null ? null : parseInt($SegmentsForm.state.intTimesJetted`${$forEachSelectedFeature2.pass}`.value.numeric)),
'Comment':$SegmentsForm.state.txtComment`${$forEachSelectedFeature2.pass}`.value
}
Another way I tried, for example:
={
'RID':$objectIds1.ids[$forEachSelectedFeature2.pass],
'TimesJetted':`($SegmentsForm.state.intTimesJetted` + `${$forEachSelectedFeature2.pass}` + `.value == null ? null : parseInt($SegmentsForm.state.intTimesJetted` + `${$forEachSelectedFeature2.pass}` + `.value.numeric))`,
'Comment':`$SegmentsForm.state.txtComment` + `${$forEachSelectedFeature2.pass}` + `.value`
}
What should I be doing here? Nested template literals? Put the whole object into backticks? Evaluate Expression before the Create Feature?
For reference, here is the form showing the segment-specific fields (3 segments worth) in Mobile:

-
Thanks to Alisa Lindley
As far as I know, dynamically calling variables is not supported in JavaScript. However, there are some workarounds we can use to accomplish certain ends. For example, the form elements can be accessed by indexing the $form.state array. So you could use an expression like:
=$TotalFootage.result + $forEach4.item.attributes["AsBuiltLength"] * $CleaningForm.state[`intTimesJetted${$forEach4.pass}`].value.numeric1 -
This is a fantastic workaround for needing to dynamically get form elements. I just needed to determine how to do this. Good to know that .state is an array of form element objects.
Thank you, Alisa! And thank you, Alex, for posting her solution.
0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
2 Kommentare