Dashboard Data Expressions for Recalculating Returns Error

1071
3
Jump to solution
05-23-2023 11:15 AM
Labels (1)
GIS_utahDEM
Frequent Contributor

Some context: I have a dashboard where I want reviewers to go in and see/edit applications. The dashboard is set up and functioning, but I'd like to set up a filter/Category Selector for the dashboard based on the reviewer (each reviewer would be looking at all the applications for specific counties, i.e. Reviewer A looks at counties X, Y and Z while Reviewer B looks at counties L, M, N and O). My idea is to have a grouped value category selector based on a Data Expression that calculates who the reviewer would be for that application based on the county.

This is what I'm trying:

 

 

var p = Portal('https://www.arcgis.com');
var fs = FeatureSetByPortalItem(p,'9cfe5d169a4e4b34a79c8640b7a924ee',0,['county'], false);

var recalc = {
  'fields': [{'name':'memberName', 'type':'esriFieldTypeString'}],
  'geometryType': '',
  'features': []
}
for(var f in fs) {
  var new_f = {'attributes': {'memberName':
 iif(fs["county"]=='Carbon'||'Beaver'||'Box Elder'||'Juab',"Jim XXXXX",
iif(fs["county"]=='Grand'||'Davis'||'Kane'||'San Juan'||'Uintah',"Kris XXXXX",
iif(fs["county"]=='Utah'||'Duchesne'||'Millard'||'Sanpete'||'Washington',"Anna XXXXX",
iif(fs["county"]=='Wasatch'||'Emery'||'Morgan'||'Sevier'||'Wayne',"Tracy XXXXX",
iif(fs["county"]=='Salt Lake'||'Garfield'||'Piute'||'Summit'||'Weber',"Chad XXXXX",
iif(fs["county"]=='Cache'||'Iron'||'Rich'||'Tooele'||'Daggett',"Alan XXXXX","Manual Review"))))))}}
  Push(recalc.features, new_f)
}
return FeatureSet(Text(recalc))

 

 

But I always get the error:

Test execution error: Execution error - Cannot access value using a key of this type. Verify test data.
 
What I'm referencing is a hosted feature layer view (though no more success with the hosted feature layer), and neither are empty. There are related tables, but I am not referencing here (layers [1] and [2] are related, but [0] is the point feature layer). 
 
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor
  • You're trying to access the field "county" from the Featureset (fs). This isn't possible, you have to do it with the Feature (f)
  • Your condition is wrong. The OR operator ( || ) combines multiple "standalone" expressions, each one has to be able to be evaluated. You want something like this:
    • f["county"] == "Carbon" || f["county"] == "Beaver || f["county"] == "Box Elder"
  • This isn't very fun to write, but that's what the Includes() function is for:
    • IIf(Includes(["County 1", "County 2", "County 3"], f["county"], ...)
  • Instead of nesting these IIf(), use When().

 

 

for(var f in fs) {
    var c = f["county"]
    var member = When(
        Includes(["C1", "C2", "C3"], c), "Member1",
        Includes(["C4", "C5", "C6"], c), "Member2",
        Includes(["C7", "C8"], c), "Member3",
        "Not assigned to any member"
    )
    Push(recalc.features, {attributes: {memberName: member}})
}

 

 


Have a great day!
Johannes

View solution in original post

0 Kudos
3 Replies
JohannesLindner
MVP Frequent Contributor
  • You're trying to access the field "county" from the Featureset (fs). This isn't possible, you have to do it with the Feature (f)
  • Your condition is wrong. The OR operator ( || ) combines multiple "standalone" expressions, each one has to be able to be evaluated. You want something like this:
    • f["county"] == "Carbon" || f["county"] == "Beaver || f["county"] == "Box Elder"
  • This isn't very fun to write, but that's what the Includes() function is for:
    • IIf(Includes(["County 1", "County 2", "County 3"], f["county"], ...)
  • Instead of nesting these IIf(), use When().

 

 

for(var f in fs) {
    var c = f["county"]
    var member = When(
        Includes(["C1", "C2", "C3"], c), "Member1",
        Includes(["C4", "C5", "C6"], c), "Member2",
        Includes(["C7", "C8"], c), "Member3",
        "Not assigned to any member"
    )
    Push(recalc.features, {attributes: {memberName: member}})
}

 

 


Have a great day!
Johannes
0 Kudos
GIS_utahDEM
Frequent Contributor

@JohannesLindner Thank you, that worked!

Any chance you also know how to add the objectID or globalid to the new recalc table? I added in lines 2, 6 and 12 but I get "Test execution error: Invalid variable assignment.. Verify test data."

 

 

var p = Portal('https://www.arcgis.com');
var fs = FeatureSetByPortalItem(p,'9cfe5d169a4e4b34a79c8640b7a924ee',0,['county','objectid'], false);

var recalc = {
  'fields': [{'name':'memberName', 'type':'esriFieldTypeString'},
  {'name':'id','type':'esriFieldTypeString'}],
  'geometryType': '',
  'features': []
}
for(var f in fs) {
  var new_f = {'attributes': {'memberName': CALCULATED}
  'id':f['objectid']}
  Push(recalc.features, new_f)
}
return FeatureSet(Text(recalc))

 

 

 

0 Kudos
JohannesLindner
MVP Frequent Contributor

Your braces in lines 11 & 12 are wrong, you have your id field outside of the attributes.

Push(recalc.features, {attributes: {memberName: member, id: f.OBJECTID}})

 


Have a great day!
Johannes
0 Kudos