I have two fields both are text and I am using the field calculator to calculate the empty field. The populated field is name "groupNames" which contains values such as below. The second field "agency" has no values and is where the calculated values are going. I am trying to use arcade to find any values in the "GroupNames" field that contain the agency acronym such as "DDOT", then calculate the empty field with "DDOT" otherwise populate with "Undefined". I have been using the Arcade statements below but cannot get them to work. Anyone have suggestions?
IIF(Find('DDOT', $feature.groupNames)== 0, "DDOT", "Undefined")
IIF(Find('DPW', $feature.groupNames)== 0, "DPW", "Undefined")
IIF(Find('CFSA', $feature.groupNames)== 0, "CFSA", "Undefined")
Thanks
Josh
Solved! Go to Solution.
If your goal is to get the agency name for each feature rather than finding the ones that are "DDOT", then you should use this.
When(Find('DDOT', $feature.groupNames) != -1, 'DDOT',
Find('DPW', $feature.groupNames) != -1, 'DPW',
Find("CFSA", $feature.groupNames) != -1, 'CFSA',
// add all the other agency names you're looking for
'undefined')
Hey @JoshLay1
Looks like you almost have it, -1 is the way to find if a result is not present, you may need to use a negation, try this out:
IIf(Find('DDOT', $feature.groupNames) != -1, "DDOT", "Undefined")
IIf(Find('DPW', $feature.groupNames) != -1, "DPW", "Undefined")
IIf(Find('CFSA', $feature.groupNames) != -1, "CFSA", "Undefined")
https://developers.arcgis.com/arcade/function-reference/text_functions/#find
Cody
Thanks for the quick reply Cody.
I tried using your expression from line 1 as a test and received the error message below.
If your goal is to get the agency name for each feature rather than finding the ones that are "DDOT", then you should use this.
When(Find('DDOT', $feature.groupNames) != -1, 'DDOT',
Find('DPW', $feature.groupNames) != -1, 'DPW',
Find("CFSA", $feature.groupNames) != -1, 'CFSA',
// add all the other agency names you're looking for
'undefined')
Thanks Ken and Cody that worked! ESRI Community is awesome!
If you have a long list of agencies to check, this might be a better way. You can modify the array of agencies easier than making a long When function
var agencies = ["DDOT", "PEMA", "CFSA"];
var output = "undefined";
for (var j in agencies) {
if (Find(agencies[j], $feature.groupNames) != -1) output = agencies[j];
}
return output