Hi
I am trying to parse out a conditional expression for visually displaying locations in Arcade (Arcgis Online) that contains two domains and I am either A, not getting the resultant I want, or B getting an error, depending on how I structure it.
if (DomainName($feature,"WA") == 8/10/2020 - 8/16/2020 && DomainName($feature,"InSta") == 'To Be Installed') {Return 'Needs to Be Installed'}
This version returns null values. Any help would be appreciated!
Solved! Go to Solution.
You have to enclose any string values in quotes. You could either use "if/else" or the IIF function to also return values that don't meet your criteria.
if (DomainName($feature,'WA') == '8/10/2020 - 8/16/2020' && DomainName($feature,'InSta') == 'To Be Installed') {
return 'Needs to Be Installed';
} else {
return "Didn't meet criteria";
}
or
iif(DomainName($feature,'WA') == '8/10/2020 - 8/16/2020' && DomainName($feature,'InSta') == 'To Be Installed', 'Needs to Be Installed', "Didn't meet criteria");
Are the domain values for "WA" strings? If so, your syntax is incorrect
if (DomainName($feature,"WA") == "8/10/2020 - 8/16/2020" && DomainName($feature,"InSta") == 'To Be Installed') {
Return 'Needs to Be Installed';
}
Otherwise, what are the values?
The domains are indeed strings. It is not a Date type column. Also the " " around "WA" should be ' '. Apologies.
Does adding the quotes around the date range help or are you still getting unexpected results?
Taking the quotes away on the date range makes it turn blue, which I am assuming is the code recognizing the Domain code/name. Removing the quotes from the 'To Be Installed' seems to nullify the expression and create an error. Otherwise, the expression will return no values which is wrong.
If I understand what you're saying, the colors change if the text is a string value (red), a function or number (blue), or part of the Javascript syntax (black). It isn't doing any compiling to recognize domain values. Are you able to supply screen shots of your expression and the data?
For example, here is one of the scripts I have that uses fields with domains. I'm not using the DomainName function, but just working with the codes. The field "Benthic Status" has three possible codes. If I click on the pencil icon for that field, it shows the codes and their names.
So in my code it is not recognizing that 'To Be Installed' Is a Code
You have to enclose any string values in quotes. You could either use "if/else" or the IIF function to also return values that don't meet your criteria.
if (DomainName($feature,'WA') == '8/10/2020 - 8/16/2020' && DomainName($feature,'InSta') == 'To Be Installed') {
return 'Needs to Be Installed';
} else {
return "Didn't meet criteria";
}
or
iif(DomainName($feature,'WA') == '8/10/2020 - 8/16/2020' && DomainName($feature,'InSta') == 'To Be Installed', 'Needs to Be Installed', "Didn't meet criteria");
That got it. Thanks you!
I noticed you used single quotes over the $feature,'Insta' and $Feature,'WA' vs my double quotes. Was that the issue?