Select to view content in your preferred language

Arcade expression returns FeatureSet but "Unable to execute Arcade script" displays in indicator

134
2
Jump to solution
a week ago
JuanTomásMartinez
Occasional Contributor

Hi,

I'm trying to create an indicator in ArcGIS Dashboards that display the percentage of features with a specific attribute value using an Arcade expression. I can see the correct result in the create new expression window, but once i click "done", the indicator displays: "Unable to execute arcade script"

For context:

  • I have a hosted feature layer with a field called "estado".
  • I want to calculate the percentage of those features where estado = 'Rechazada IPEEM/Archivo'.
  • Running the script in the create new expression window returns the FeatureSet correctly.
  • Log window doesn't display any warnings or errors.
var capa = FeatureSetByPortalItem(
  Portal(''),
  '597723f82afb4031a8211a2a993c7688', // Feature layer ID
  0,
  ['estado']
);

var total = Count(capa);
var rechazadas = Count(Filter(capa, "estado = 'Rechazada IPEEM/Archivo'"));

var porcentaje = IIf(total == 0, 0, Round((rechazadas / total) * 100, 1));

return {
  fields: [
    { name: "porcentaje", type: "esriFieldTypeDouble" }
  ],
  geometryType: "",
  features: [
    {
      attributes: {
        porcentaje: porcentaje
      }
    }
  ]
};

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You are returning a Dictionary, not a FeatureSet. You just need to wrap that Dictionary in the FeatureSet function

var capa = FeatureSetByPortalItem(
  Portal(""),
  "597723f82afb4031a8211a2a993c7688",
  0,
  ["estado"]
);

var total = Count(capa);
var rechazadas = Count(Filter(capa, "estado = 'Rechazada IPEEM/Archivo'"));

var porcentaje = IIf(total == 0, 0, Round(rechazadas / total * 100, 1));

return FeatureSet(
  {
    fields: [{ name: "porcentaje", type: "esriFieldTypeDouble" }],
    geometryType: "",
    features: [{ attributes: { porcentaje: porcentaje } }]
  }
);

View solution in original post

2 Replies
NicoleJohnson
Frequent Contributor

Try something like this, I think you've mostly got it:

// Point to Portal
var p = Portal('https://maps.arcgis.com/')

// Create featureset
var fs = FeatureSetByPortalItem(p, '5c798c532ad5448ea9e973de8ddf8076', 2, ['State'], false)

var total = Count(fs)

var michigan = Count(Filter(fs, "State = 'Michigan'"))

// Calculate percent
var pct = IIf(total == 0, 0, Round((michigan / total) * 100, 1))

// Create dictionary to hold percent calculation
var newDict = {fields: [
    {name: 'Percent', type: 'esriFieldTypeDouble'}],
    geometryType: '',
    features: []
}

// Put percent calculation into dictionary
Push(newDict['features'], {attributes: {Percent: pct}})

// Create a featureset from the dictionary
return FeatureSet(Text(newDict))
KenBuja
MVP Esteemed Contributor

You are returning a Dictionary, not a FeatureSet. You just need to wrap that Dictionary in the FeatureSet function

var capa = FeatureSetByPortalItem(
  Portal(""),
  "597723f82afb4031a8211a2a993c7688",
  0,
  ["estado"]
);

var total = Count(capa);
var rechazadas = Count(Filter(capa, "estado = 'Rechazada IPEEM/Archivo'"));

var porcentaje = IIf(total == 0, 0, Round(rechazadas / total * 100, 1));

return FeatureSet(
  {
    fields: [{ name: "porcentaje", type: "esriFieldTypeDouble" }],
    geometryType: "",
    features: [{ attributes: { porcentaje: porcentaje } }]
  }
);