Select to view content in your preferred language

Using Arcade to calculate a field based on the value of another field

1515
2
Jump to solution
09-21-2023 01:02 PM
AlcoGISUser
Emerging Contributor

I'm creating a smart form for Field Maps and one of the requirements is to toggle one of the entries to either "Yes" or "No" using a switch. I have the default value set to "No". If the person in the field toggles the switch to "Yes" I want an Arcade expression to update the value for that same record in a date field with the current date of when the switch was toggled to "Yes" for that record.

I tried this but got an error:

var inspection_date = $feature.DATE_INSPECTED; /// date field to be changed with Arcade expression

var inspected = $feature.INSPECTED; /// toggle switch field

IIf(inspected = "Yes", inspection_date = Today(), null); /// condition
 
The error I get is:
 
Test execution error: Execution error - undefined. Verify test data.
 
I think I may need to use a for loop to achieve this but not sure how a response in a smart form would trigger the expression. Is this even possible? 
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

When writing any logical function (either IF or IFF), you have to use "==" when evaluating a condition

var inspection_date = $feature.DATE_INSPECTED; /// date field to be changed with Arcade expression
var inspected = $feature.INSPECTED; /// toggle switch field
IIf(inspected == "Yes", inspection_date = Today(), null); /// condition

 

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

When writing any logical function (either IF or IFF), you have to use "==" when evaluating a condition

var inspection_date = $feature.DATE_INSPECTED; /// date field to be changed with Arcade expression
var inspected = $feature.INSPECTED; /// toggle switch field
IIf(inspected == "Yes", inspection_date = Today(), null); /// condition

 

AlcoGISUser
Emerging Contributor

Duh, I overlooked that. Weirdly enough the field populates in map viewer but not in field maps. 

0 Kudos