I have been using Arcade expressions for custom popups. These are being authored in ArcGIS Pro for later deployment to AGOL.

These expressions are all being named, can be successfully embedded in the pop-up title and text elements, and are also listed in the fields list.

As these expressions grow in complexity I find I am copy/pasting snippets from one expression to another, I would like to avoid this duplication.

I have tried to extract the common logic to a separate expression but don't seem to be able to call one expression from another.

As an example I have an expression named SAMPLE_NAME and it can be embedded in the title as {expression/SAMPLE_NAME}.

However each of the following lines produces a "Field not found..." error.

var a = $feature["SAMPLE_NAME"];
var b = $feature["expression/SAMPLE_NAME"];
var c = $feature["{expression/SAMPLE_NAME}"];
var d = $feature.SAMPLE_NAME;

Is it possible to call one expression from another? If so how?

Alternatively can I export/import functions between expressions or otherwise reduce the need to duplicate code?


Unfortunately, you're not able to call defined functions across multiple expressions. In the Map Viewer, there is the Existing tab of the expression editor.

existing tab

This tab will let you bring in expressions referenced elsewhere in the same layer. It's not quite the same as referencing the same function. If I have two expressions with identical functions in them, I'm really calling that function twice.

Also, this tab is essentially a glorified copy and paste. Adding an existing function does not "link" it to the function. If I go and edit the referenced function and come back, the changes will not be reflected.

As an alternative, if you have lots of interrelated expressions, you could have them all as part of a single expression which returns a list or dict, rather than a separate expression for each value. This somewhat limits your formatting options for your popup, but may be simpler.

var outDict = Dictionary('a', 'A',
    'b', 12,
    'c', 'Something Else')

var outstr

for(var d in outDict){
    outstr += d + ' : ' + outDict[d] + '\n'
return outstr


a : A
b : 12
c : Something Else

Instead of defining the dictionary values directly as I have in my example, you could just as easily call custom functions defined earlier in your expression, i.e.:

function funcOne(...){...};
function funcTwo(...){...};

var outDict = Dictionary('first field', funcOne(someValue),
    'second field', funcTwo( someOtherValue),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.