Arcade Popup Not Getting Sum of values from loop expression

1015
3
07-09-2019 04:20 PM
JamesFaron
Occasional Contributor

I am implementing a custom expression which gets the result, a sum where applicable (i.e.when there are more than one results). The expression tests successfully in the expression editor, but the popup only returns the first result, i.e. does not get the sum of multiple results. The following expression yields a result of 24 when Test is clicked in the Expression editor, but the popup yields only the first of the three (in this case) results, the number 8 in this  case (three results with the value of 8 each). Here is the code, followed by a screenshot of the test result, and then the popup on the map (the attribute in question is the last line (Total kW on Applications).

var fc = FeatureSetById($map, /* PowerClerk Application Approved */ "DG_Transformer_Availability_Popup_test_2658")
var code = $feature["PARENT_ID"]
//var pizza = 26712474;
var sql = "TRANSFORMER_ID = " + code;
//var sql = "TRANSFORMER_ID = " + pizza;
//var sql = "TRANSFORMER_ID = 12157630"
Console(sql);
var applications = Filter(fc, sql);
var cnt = Count(applications);
Console(cnt);
var getAppKW;
var sumAppKW = 0;
if(cnt > 0){
Console(cnt);
for (var application in applications){
sumAppKW += application.APPLICATION_KW_AC
}
getAppKW = sumAppKW
}else{
getAppKW = "N/A"
}
if (IsEmpty(getAppKW) || (getAppKW == NULL)){
getAppKW = "No Data"
}
Console(getAppKW);
return getAppKW

Expression TestPopup Result

The line in the popup configuration (custom attribute display) is 'Total kW on Applications: {expression/expr5}', where expr5 is the expression quoted above.  This is on Portal for ArcGIS, 10.7.1. It seems that the Popup does not wait for the loop to complete, or there is an error or flaw in the code?

Thanks,

Jim Faron

Unisource Energy

0 Kudos
3 Replies
XanderBakker
Esri Esteemed Contributor

Hi jfaron44 

The thing that I notice is that your are comparing your PARENT_ID to the TRANSFORMER_ID. Is that correct?Some minor adjustments to the code (however, this will not solve your problem):

var fc = FeatureSetById($map, "DG_Transformer_Availability_Popup_test_2658");
var code = $feature["PARENT_ID"];
var sql = "TRANSFORMER_ID = " + code;
Console(sql);

var applications = Filter(fc, sql);
var cnt = Count(applications);
Console(cnt);

var getAppKW;
var sumAppKW = 0;
if(cnt > 0){
    for (var application in applications){
        sumAppKW += application.APPLICATION_KW_AC;
    }
    getAppKW = sumAppKW;
} else {
    getAppKW = "N/A";
}

if (IsEmpty(getAppKW) || (getAppKW == null)){
    getAppKW = "No Data";
}

Console(getAppKW);
return getAppKW;

Can you post back what your console is reporting?

0 Kudos
JamesFaron
Occasional Contributor

Hi Xander,

Thank you for the response, and for your previous blog posts, they are very helpful. The PARENT_ID field data is equal to the TRANSFORMER_ID field in the related feature class.

I don't know if it's gremlins on the internet, or more likely a caching issue in the browser, but when I tried it this morning after reopening the application, it works as expected! I guess I'll do more developing in incognito window to eliminate that issue going forward, although I will also keep testing to see if there is any latency issue at work. The console was accurate, but the Popup was not, as described in my initial post, so it does seem pretty strange.

Thanks!

Jim Faron

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi James Faron ,

I have had problems in the past depending on the browser and one time it was an update issue of Chrome that prevented the code to work. Glad to hear that your is working, that is the most important part! 

0 Kudos