ArcGIS Operations Dashboard Arcade Join Table

3285
6
Jump to solution
01-04-2022 07:56 AM
Norchevskyi
New Contributor II

Hi,

I'm trying to create Arcade Expression, that will join the feature layer and a feature table for different widgets in Operations Dashboard, but my expression cannot load the data, please help me, as I suspect that something was not provided for in the code of this expression.

 

 

var portal = Portal("https://www.arcgis.com/");
var polyfs = FeatureSetByPortalItem(portal,"2c70f00e262a4488b266595720312617",0,["*"],true);
var tablefs = FeatureSetByPortalItem(portal,"227503e1ba6848baa7227b6311c04802",0,["*"],false);

var joinedDict = {
  fields: [
    { name: "StreetID", type: "esriFieldTypeInteger" },
    { name: "Name", type: "esriFieldTypeString" },	
    { name: "Depth", type: "esriFieldTypeFloat" },
  ],
'geometryType': '',
'features':[]};

var i = 0;
for (var t in tablefs) {
    var tableID = t["StreetID"]
    for (var p in Filter(polyfs, "StreetID = "+tableID)){
        joinedDict.features[i] = {
            attributes: {
                StreetID: tableID,
                Name: p["Address"],
				Depth: t["Depth"],
            }
        }
    }
i++
}

return FeatureSet(Text(joinedDict));

 

 

Thank you,

Roman

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Ah, I see it now. You are trying to cast the Depth as a "float", which isn't in the list of field types you can use (even though it is a valid data type in other contexts).

Change that to 'esriFieldTypeDouble' and it evaluates just fine:

jcarlson_0-1641316160739.png

 

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
6 Replies
jcarlson
MVP Esteemed Contributor

I would guess it has something to do with that Filter statement, but since the layers aren't shared publicly, it's hard to say for sure. Usually when referencing a variable in your expression string, you should put it in the string itself in the format @variableName. Try this to see if the output changes.

var i = 0;
for (var t in tablefs) {
    var tableID = t["StreetID"]
    var filt_poly = Filter(polyfs, "StreetID = @tableID")
    for (var p in filt_poly){
        joinedDict.features[i] = {
            attributes:
                StreetID: tableID
                Name: p["Address"],
                Depth: t["Depth"],
            }
        }
    }
i++
}

 

- Josh Carlson
Kendall County GIS
0 Kudos
Norchevskyi
New Contributor II

Hi Josh,

Thanks for your answer, I applied your recomendations, but it not working. When I click Test button, I don't see error:

Norchevskyi_0-1641314525982.png

But after click Done button I see error in the expression:

Norchevskyi_1-1641314643696.png

 

I shared this services as public for everyone,

Thank you,

Roman

 

0 Kudos
jcarlson
MVP Esteemed Contributor

Ah, I see it now. You are trying to cast the Depth as a "float", which isn't in the list of field types you can use (even though it is a valid data type in other contexts).

Change that to 'esriFieldTypeDouble' and it evaluates just fine:

jcarlson_0-1641316160739.png

 

- Josh Carlson
Kendall County GIS
0 Kudos
Norchevskyi
New Contributor II

Josh, thank you very much, it is working

Roman

0 Kudos
RussellLundstrumUSACE
New Contributor II

A follow up question to data types- when I try to define a date, there is not an error, but nothing is returned. Example below I modified from github here

I added lines 33 and 48 to get the ForecastTime which is a date field in the source, but when it is defined as "esriFieldTypeDate" in line 48, the Test fails. If you change it to "esriFieldTypeString" it works. But I want to have a date type to work with in the dashboard. Are dates not supported or am I missing something else?

 

var portal = Portal("https://www.arcgis.com/");
var polyfs = FeatureSetByPortalItem(
    portal,
    "4dbbad3d6f694e0ebc7c3b4132ea34df",
    0,
    ["*"],
    false
);

var tablefs = FeatureSetByPortalItem(
    portal,
    "4dbbad3d6f694e0ebc7c3b4132ea34df",
    6,
    ["*"],
    false
);

// Create empty features array and feat object
var features = [];
var feat;

// Populate Feature Array
for (var t in tablefs) {
    var tableID = t["FeatureID"]
    for (var p in Filter(polyfs, "HydroID = "+tableID)){
        feat = {
            attributes: {
                FeatureID: tableID,
                Name: p["DPS_Region"],
				ModelID: t["ModelID"],
                AddressCount: t["AddressCount"],
                MAX_TSTime: t["MAX_TSTime"],
                ForecastTime: t["ForecastTime"],
            }
        }

    Push(features, feat)
    }
}

var joinedDict = {
    fields: [
        { name: "FeatureID", type: "esriFieldTypeString" },
        { name: "Name", type: "esriFieldTypeString" },	
        { name: "ModelID", type: "esriFieldTypeInteger" },
        { name: "AddressCount", type: "esriFieldTypeInteger" },
        { name: "MAX_TSTime", type: "esriFieldTypeString" },
        { name: "ForecastTime", type: "esriFieldTypeDate" },
    ],
    'geometryType': '',
    'features':features
};

// Return dictionary cast as a feature set 
return FeatureSet(Text(joinedDict));

 

EDIT: I found help from a co-worker- added number() in the attribute array on line 33 above:

ForecastTime: number(t["ForecastTime"]),

ForecastTime: number(t["ForecastTime"]),

 

0 Kudos
Manager_HMWSSBCDC
New Contributor II
var item_id = '99646c55510049a583bc1fe853c7f5f0';
var fields = ['docketcode','objectid'];
var tankers_table = FeatureSetByPortalItem(portal, item_id, 4, fields, false);

 

// return tankers_table

 

var item_id2 = '7a28dc5aad08489ea8ce46f8eeedb51e'
var fields_2 = ['fs_name','docketno','objectid']

 

var fs_table = FeatureSetByPortalItem(portal, item_id2, 6, fields_2, false)
// return fs_table




var joinedDict = {
  fields: [
    { name: "docket", type: "esriFieldTypeString" },
    { name: "Name", type: "esriFieldTypeString" },  
    { name: "fsName", type: "esriFieldTypeString" },
  ],
'geometryType': '',
'features':[]};

 

var i = 0;
for (var t in fs_table) {
    var tableID = t["docketno"]
    var filt_tanker = Filter(tankers_table, "docketcode = @tableID")
    for (var p in filt_tanker){
        joinedDict.features[i] = {
            attributes: {
                docket: tableID,
                Name: p["docketcode"],
                fsName: t["fs_name"],
            }

 

        }
    }
i++
}



return FeatureSet(Text(joinedDict));


Error message i'm getting is 

Test execution error: Execution error - Out of bounds. Verify test data.


Please help me to find where the error was.
0 Kudos