Data expression does not always execute properly

525
1
Jump to solution
05-21-2021 06:48 AM
erica_poisson
Occasional Contributor III

Hi,

I have a data expression (below) which executed properly when I was testing the data expression and configuring my chart in my Dashboard. After I saved and refreshed, it was no longer executing properly and does not show all of the data. Sometimes all data is returned, and other times it is not.

For example, this is what the chart should look like (it does look like this sometimes)

erica_tefft_0-1621604713755.png

Then if I refresh, I see this:

erica_tefft_1-1621604802696.png

 

Here is my data expression:

var portal = Portal("https://www.arcgis.com");
// Create a FeatureSet for stable and unstable inspections. 
// Group the features by the BLA 

var BLA = FeatureSetByPortalItem(portal,"###",0,['BLA_Used'],false);

var groupBLA = GroupBy(BLA,
  ["BLA_Used"],
  [
    { name: "BoatLaunchArea", expression: "BLA_Used", statistic: "COUNT" },
  ]
);

var combinedDict = {
  fields: [
    { name: "BLA", type: "esriFieldTypeString" },
    { name: "cntSurveyScans", type: "esriFieldTypeInteger" },
  ],
  geometryType: "",
  features: [],
};

var i = 0;

for (var m in groupBLA) {
  combinedDict.features[i] = {
    attributes: {
      BLA: m["BLA_Used"],
      cntSurveyScans: (m["BoatLaunchArea"] / 2),
    },
  };
  i++;
}

return FeatureSet(Text(combinedDict));

 

 

This feature layer is updated frequently by Survey123. Could the frequent updates to the layer be causing these issues?  This layer also has 8,000 records and counting. 

 

Any advice would be appreciated!

Erica 

Erica
0 Kudos
1 Solution

Accepted Solutions
erica_poisson
Occasional Contributor III

I figured this out - the occasional decimal value was messing this up. The correct data expression now reads:

var portal = Portal("https://www.arcgis.com");
// Group the features by the BLA 

var BLA = FeatureSetByPortalItem(portal,"xxx",0,['BLA_Used'],false);

var groupBLA = GroupBy(BLA,
  ["BLA_Used"],
  [
    { name: "BoatLaunchArea", expression: "BLA_Used", statistic: "COUNT" },
  ]
);

var combinedDict = {
  fields: [
    { name: "BLA", type: "esriFieldTypeString" },
    { name: "cntSurveyScans", type: "esriFieldTypeInteger" },
  ],
  geometryType: "",
  features: [],
};

var i = 0;

for (var m in groupBLA) {
  combinedDict.features[i] = {
    attributes: {
      BLA: m["BLA_Used"],
      cntSurveyScans: (Floor(m["BoatLaunchArea"] / 2)),
    },
  };
  i++;
}

return FeatureSet(Text(combinedDict));
Erica

View solution in original post

0 Kudos
1 Reply
erica_poisson
Occasional Contributor III

I figured this out - the occasional decimal value was messing this up. The correct data expression now reads:

var portal = Portal("https://www.arcgis.com");
// Group the features by the BLA 

var BLA = FeatureSetByPortalItem(portal,"xxx",0,['BLA_Used'],false);

var groupBLA = GroupBy(BLA,
  ["BLA_Used"],
  [
    { name: "BoatLaunchArea", expression: "BLA_Used", statistic: "COUNT" },
  ]
);

var combinedDict = {
  fields: [
    { name: "BLA", type: "esriFieldTypeString" },
    { name: "cntSurveyScans", type: "esriFieldTypeInteger" },
  ],
  geometryType: "",
  features: [],
};

var i = 0;

for (var m in groupBLA) {
  combinedDict.features[i] = {
    attributes: {
      BLA: m["BLA_Used"],
      cntSurveyScans: (Floor(m["BoatLaunchArea"] / 2)),
    },
  };
  i++;
}

return FeatureSet(Text(combinedDict));
Erica
0 Kudos