Data Expression Needing to Return an Empty Feature Set

154
4
2 weeks ago
Labels (1)
AlinaTarmu_SCGIS
New Contributor III

Is it normal behavior for a dashboard data expression to display "Unable to Execute Arcade Script" if it needs to return an empty feature set? When testing, the script executes as it should, it codes a dynamic indicator that at this point should display zero. Is there a workaround for this issue?

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

Can you post your script? Does it return an empty FeatureSet or the number 0?

0 Kudos
AlinaTarmu_SCGIS
New Contributor III

It returns an empty feature set. I created another script that returns an empty feature set and that one indeed works fine (thanks, @jcarlson!). It might be something in the script (or data, or most likely portal).  Here it is:

 

 

 

// declaring portal variable
var portal = Portal("https://myportal.com/portal");
// filter work order feature set for required fields
var fs = Filter(
  FeatureSetByPortalItem(
    portal,
    '3f959g85g959595954ff9ggkdkgr',
    0,
    ["OBJECTID", "EQUIPMENT", "STATUS", "DATE_CREATED"],
    false,
    ),
  "STATUS LIKE 'Not Performed' AND PM_CODE LIKE 'SG-100SW-3'"
)

//generating an array of equipment values that have consecutive Not Performed cycles
var pairs = []
for (var r in fs) {
    var keys = r["EQUIPMENT"];
    var values = r["DATE_CREATED"];
    var keyvalue = {"key": keys, "value": values}
    Push(pairs, keyvalue)
}

var resultArray = [];
for (var i = 0; i < Count(pairs)-1; i++) {
  var current = pairs[i];
  var next = pairs[i + 1];

  if (Equals(current.key, next.key) && Abs(DateDiff(Date(current.value),Date(next.value), "days")) <= 93) {
    Push(resultArray, current.key);
    }
}
//adding single quotes to the strings in the array so that the SQL filter recognizes them in order to match them to the equipment layer
var newFilter = [];
for (var i = 0; i< Count(resultArray)-1; i++) {
    var string = "'" + resultArray[i] + "'";
    newFilter[i] = string
    }

var eqFilter = `EQUIPMENT IN (${Concatenate(newFilter, ',')})`

//filtering the equipment layer for the equipment values in the array
return Filter(FeatureSetByPortalItem(
    portal,
    'otmbd4968695gmb09fkv99vkvv',
    0,
    ['*'],
    false,
    ),
eqFilter)

 

 

 

 

 

This script works perfectly for two other PM codes, with 31, respectively 62 days. 

 

0 Kudos
jcarlson
MVP Esteemed Contributor

What is your expression actually returning? Can you share the code?

Returning an empty data expression is possible, and works just fine.

jcarlson_0-1715184529816.pngjcarlson_1-1715184537955.png

 

- Josh Carlson
Kendall County GIS
AlinaTarmu_SCGIS
New Contributor III

Today my other two data expressions, which were working perfectly, display the same error. SO IT IS DEFINITELY NOT THE CODE. 😀  (This issue is related to the other issue I posted, with the chart built on a data expression not interacting with other dashboard elements, issue to which Josh answered.)

(Also: thank goodness for the Arcade Playground...)

0 Kudos