Select to view content in your preferred language

Field Maps expression: calculate attribute if another attribute is null

186
3
4 weeks ago
RasmusRaun
New Contributor

Hi

Is it possible to make an expression in my Field maps formula, where the value of attribute1 (an integer) = 4 if the value of attribute2 (a string) is not null. 

Regards Rasmus

0 Kudos
3 Replies
NathanDavis
Occasional Contributor

Hi, 

This is possible - it will require you to have an editability expression and a value expression on attribute1.

editability expression must return 'false' if you want the value to calculate, so it would look like:
if (IsEmpty($feature.attribute2)) { return true };
return false;

value expression just needs to handle the calculation: (this won't fire if editability = false)
if (!IsEmpty($feature.attribute2)) { return 4 };

0 Kudos
JamesMiller36
Emerging Contributor

Yes, you can do this with an Arcade expression in Field Maps.
Example:

if (!IsEmpty($feature.attribute2)) {
return 4;
} else {
return $feature.attribute1;
}


This sets attribute1 = 4 only when attribute2 is not null. Otherwise, it keeps the original value.

0 Kudos
RasmusRaun
New Contributor

Thanks for the answers. I tried both solutions (replacing attribute1/2 with the actual field names of course) but I keep getting an error when i try to save stating that the formula is invalid. 

0 Kudos