Arcade Expression in Pop-Up Error:15

1170
13
01-15-2021 02:06 PM
DanielWalsh
New Contributor II

Hello, 

We were very happy to see that Arcade expressions are supported in Field Maps and were hoping to use it to generate unique IDs in the field that can be referenced on reports, project documents. We developed an Arcade expression that does this and it works when loaded into the Beta Map viewer. However when opened in Field Maps we get an error code 15, Evaluation_error_code::unknown_function Line :20. I got the expression to work in Field Maps by removing many of the functions which unfortunately make it no longer meet our needs. Does anyone know if there is only a subset of the Arcade library that will work in Field Maps?

Thanks in advance for any help!

Below is the expression that has been developed:

var choices = {}; 
choices['1'] = 'BLD'; 
choices['2'] = 'STR'; 
choices['3'] = 'PAD'; 
choices['4'] = 'PIT'; 
choices['99'] = 'OTH'; 

function formatMulti(inField, d) {
    var values = Split(inField, ',');
    var labels = [];
    for (var i in values){
        labels[i] = d[values[i]];
    }
    var outText = Concatenate(labels, TextFormatting.NewLine);
    return outText;
}
var park = IIf(IsEmpty($feature.SiteID), "UNK", Right(Left($feature.SiteID, 6), 3));
var yr = Text($feature.CreationDate, 'YY');
var tpe = formatMulti($feature.Type, choices);
var unique_val = $feature.Creator + $feature.CreationDate;
var hashed = Round(Sqrt(Hash(unique_val)), 0);
var new_id = park + "-" + yr + "-" + tpe+hashed;

return new_id

 

Tags (2)
13 Replies
MikeSlattery
Occasional Contributor

Interested to see what the answer is; I hope you get resolution. 

ESRI team, things seem to be moving fast toward parity, but is there a chart that gives a matrix of supported arcade calls across products?

Multi support in Field Apps through to feature layer storage could be very interesting...  I didn't know that had expanded past the xlsform world.

0 Kudos
ChrisDunn1
Esri Contributor

Hi Mike,

There is a version matrix you can use as a reference here: https://developers.arcgis.com/arcade/guide/version-matrix/. Field Maps is currently built on version 100.9 of the Runtime SDK, so it supports functions up to Arcade version 1.11, with the exception of a few specific functions outlined in footnote 4. 

DanielWalsh
New Contributor II

This is fantastic Chris, exactly what I was looking for!

0 Kudos
AZietara
New Contributor II

Hi @ChrisDunn1  ,

I have a similar question. I have several Arcade expressions which use function "Count". It works fine in Web Map, however when I try to open pop-up in Field Maps I get an error:

Error Code:15

Error Description: Invalid call., Unable to evaluate arcade expression.

Evaluation_error_code::general_evaluation_error Line XX

Line number is always indicating the line with "Count" funcion that's why I suppose it is the one which is problematic. In version-matrix you sent it is stated that "Count" for FeatureSet is supported since version 1.5. If Field Maps supports functions up to Arcade version 1.11, I am not sure why it is not working. Do you have any suggestions?

0 Kudos
ChrisDunn1
Esri Contributor

Hi @AZietara ,

The Count function should work, so it's likely the problem is the object being passed into Count. Count will accept a feature set, an array, or a string, so make sure that is what's being counted and make sure it can't be null as I could see that causing an error, you could always add a check for null before the count statement.

You can get some more info by including a console statement, so if your count statement is something like;

Count(myObject)

Then just before that use;

Console(myObject)

And when you hit test switch to the Messages and you'll see what the object is that's being passed into Count.

If this doesn't help you track down the issue feel free to post the full expression if you can.

0 Kudos
AZietara
New Contributor II

Thank you for your answer @ChrisDunn1 !

Input of count is a feature set but it looks that the issue appears when it has no records. I use FeatureSetByName to get records from related table and for some objects there are no records. How can I add a check for null before the count statement? Tried to use IsEmpty function, but it returns 'False' when there are no records in my feature set. 

Below you can find my code. As I wrote before - everything is working fine in Web Map i AGOL. When I try to use Field Maps, I get an error:

* for empty feature set the error refers to line with statement "var mycount = Count(utl_f)", so IsEmpty returns "false" for empty feature set

* for feature set with some objects, the Count function seems to be working, but error refers to line with the statement "var dismarray = Distinct(marray)". Are there also any special conditions for Distinct function to make it work in Field Maps?

 

var parsellnr = $feature.parsellid
var utl = FeatureSetByName($map, 'utløpsgrøft - tilstand')

var sql1 = "parsellid = '" + parsellnr + "' ";
var sql2 = " AND tilstand = '2' "
var sql = sql1 + sql2
var utl_f = Filter(utl, sql)

if (!IsEmpty(utl_f)){
    var mycount = Count(utl_f)
}

var marrayix = 0
var marray = []
var antunik = 0

if (mycount>0) {
    for (var c in utl_f){
        var glid = c.utlopsgroft_ID
        marray[marrayix]= glid
        var dismarray = Distinct(marray)
        ++marrayix
    }
    var antunik = Count(dismarray)
}
return antunik

I really appreciate your help,

Aleksandra

 

 

0 Kudos
AZietara
New Contributor II

@ChrisDunn1 can it be a general problem with Feature Set not validating when being empty?

I have tested couple of different checks for null values. The one presented in previous comment with IsEmpty() function which returns 'false' for empty dataset. 

The other one which adds First() function before IsEmpty() function. It works fine, as then the value is 'true' in Web Map, however, it fails on this line in Field Maps apps. 

 

var mycount = 0
if (!IsEmpty(First(utl_f))) {
    for (var i in utl_f){
        mycount =+1
    }
}

 

 

I have also tried with common for loop, but Field Maps returns error for this one too. 

 

var mycount = 0
for (var i in utl_f){
    mycount =+1
}

 

 

I would love to hear about possibilities of adding a check for null as you suggested. 

0 Kudos
ChrisDunn1
Esri Contributor

Hi @AZietara - sorry for the delay. I'm still digging into this but I have learned a few things.

IsEmpty will only return true for null and empty strings, if you use it with an empty array it will still return false which is why IsEmpty(utl_f) returned false but IsEmtpy(First(utl_f)) returns true. This snippet you posted above seems like it should work.

 

var mycount = 0
if (!IsEmpty(First(utl_f))) {
    for (var i in utl_f){
        mycount =+1
    }
}

 

Which line exactly is it failing on in Field Maps?

0 Kudos
AZietara
New Contributor II

Hello @ChrisDunn1 and thank you for reply!

Yes, it looks like IsEmpty() is not meant to be used with arrays. 

The behavior of First() is the same as for Count(). It validates for NOT empty Feature Sets, but error in Field Maps appears for Feature Set with no records. The line it fails is the one containing First(utl_f). Tried with the whole expression if(!IsEmpty(First(utl_f))) but also to write just First(utl_f) in a separate line and it is the one causing troubles. So it looks that First() also have some limitations.. I wonder if there are any other functions I could use here?

0 Kudos