Select to view content in your preferred language

result of Arcade expression is showing object object in column

2525
10
Jump to solution
01-02-2023 02:07 AM
Labels (1)
spiderman90
Emerging Contributor

 

Hello ,

i have used the iexpression here but i changed only the attributes name as my data and it works when i click on test ,i got the result that i want 

https://github.com/Esri/arcade-expressions/blob/master/dashboard_data/JoinLayerFieldsToTable.md

but after i added that expression to my table ,when i check the table of the layer in map viewer classic , it has automatically added the new attribute  as i want  but  it is showing object object in column.

i would like to show only the result  values from the expression  that i have brought from other table . 

 

 

Thanks in advance

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
CarmelConnolly
Esri Regular Contributor

Hi, can you explain the workflow you're doing to get to the above screenshot?

To have 'result' as part of the layer so it can be exported, I believe it needs to follow a workflow like: 

  1. Add a new field to the layer schema called 'result' https://doc.arcgis.com/en/arcgis-online/manage-data/add-or-delete-fields.htm#GUID-BE260302-CEA6-4A3A...
  2. Calculate values for the 'result' field using the same Arcade expression following https://doc.arcgis.com/en/arcgis-online/manage-data/calculate-fields.htm#ESRI_SECTION1_4EC0FE85CA914... CarmelConnolly_0-1672823753362.png
  3. The attributes will now be part of the layer and its schema. Note that this calculation is static and not dynamic like a Pop-up > Attribute Expression (if that's what you've been using)

View solution in original post

0 Kudos
10 Replies
spiderman90
Emerging Contributor

Hello ,

i did the same idea but i need to know , how to continue to show only the value of specific attribute as a result . 

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"],
            }
        }

    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" },
    ],
    'geometryType': '',
    'features':features
};

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

could someone advice me ? 

i need to show field values in the table as result of expression .

i have read alot of articles and i understood that i have to grab the feature and access attributes from feature set . 

i did not get the idea yet .

could some one explain me, how to access feature in feature set and grab specific attribute with values as a result of function 

0 Kudos
CarmelConnolly
Esri Regular Contributor

Hey, what are you expecting it to return in the field?

It's returning [object Object] which is representing the entire feature set, including all features, their geometry and attributes.

I don't think this code sample is the most efficient way to do what you want, but I've modified it narrow in on the specifc row ($feature) that's being calculated to generate a string of the attributes of the individual tablefs FeatureID ($feature) based on the matching polyfs HydroID (I've assumed this calculation is based on the tablefs item:

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

// Create empty feat variable
var feat;

// Populate Feature Array
var tableID = $feature["FeatureID"];
var p = First(Filter(polyfs, "HydroID = "+tableID));
feat = "FeatureID: " + tableID + "," + TextFormatting.NewLine +
       "Name: " + p["DPS_Region"] + "," + TextFormatting.NewLine +
       "ModelID: " + $feature["ModelID"] + "," + TextFormatting.NewLine +
       "AddressCount: " +$feature["AddressCount"] + "," + TextFormatting.NewLine +
       "MAX_TSTime: " +$feature["MAX_TSTime"] + "," 

// Return feat string
return feat;

  It'll look like this based on the above formatting: 

CarmelConnolly_0-1672763077070.png

 

0 Kudos
spiderman90
Emerging Contributor

Thanks alot ,it is doing what i want . but i have still question .

Does it possible to show the output automatically without clicking  on show? 

 

i am doing this expression in web map ,so could be the new attribute to add to layer ?and how could i export the data from web map ? 

Thanks alot for help ,i have spent lots of time to try to solve my problem .

0 Kudos
CarmelConnolly
Esri Regular Contributor

Hi, can you explain the workflow you're doing to get to the above screenshot?

To have 'result' as part of the layer so it can be exported, I believe it needs to follow a workflow like: 

  1. Add a new field to the layer schema called 'result' https://doc.arcgis.com/en/arcgis-online/manage-data/add-or-delete-fields.htm#GUID-BE260302-CEA6-4A3A...
  2. Calculate values for the 'result' field using the same Arcade expression following https://doc.arcgis.com/en/arcgis-online/manage-data/calculate-fields.htm#ESRI_SECTION1_4EC0FE85CA914... CarmelConnolly_0-1672823753362.png
  3. The attributes will now be part of the layer and its schema. Note that this calculation is static and not dynamic like a Pop-up > Attribute Expression (if that's what you've been using)
0 Kudos
spiderman90
Emerging Contributor

Hi , 

Thanks alot i got what u mean .

but when i use the same expression  by calculate in layer ,i have found that it is not working because of map is not defined .

Execution Error:Runtime Error: Identifier Not Found. $map

i know that i can access to other layer by define variable portal and so on ,but i do not have at this moment the accessible to do it . 

is there other method to read from other layers ?

0 Kudos
CarmelConnolly
Esri Regular Contributor

Can you share the code you're using in the Calculate? 

What do you mean by 'but i do not have at this moment the accessible to do it . '? Is the layer shared with you?

0 Kudos
Sergio
by
Emerging Contributor

Hello Carmel! 

I get - "Execution Error:Database error has occurred" when trying to execute your example. 

To be precise the execution fails once I enter this lines:

 var p = First(Filter(polyfs, "HydroID = "+tableID));

or:

for (var p in Filter(polyfs, "HydroID = "+tableID)){}

like in initial example. The only difference in my code is that I call feature class and table straight from the map like this:

var polyfs = FeatureSetByName($map,"FC_polyfs")

var tablefs = FeatureSetByName($map,"T_tablefs")

and I'm doing this in on-prem portal not in AGOL.

I'm new to Arcade but was looking for the way to make a sort of join when you have one geometry feature and multiple table features displayed in popup (at least) joined by common field. Example you are discussing here seems very similar to what I'm trying to achieve. Maybe you can advise a better way?

Thank you!

Regards

0 Kudos
CarmelConnolly
Esri Regular Contributor

Hi @Sergio , 

What version of ArcGIS Enteprise are you using? This is to check that Arcade functions are available at this version. 

What field data type is 'HydroID'? If it's string field, you'll need quotes in the SQL query: 

 

Filter(polyfs, "HydroID = '"+tableID+"'")

 

At what stage of your script is it failing? Use the console() function, Test, and Messages tab to see how far the script runs to. Something like: 

 

var portal = Portal("https://www.arcgis.com/");
console("Runs to portal")
var polyfs = FeatureSetByPortalItem(
    portal,
    "4dbbad3d6f694e0ebc7c3b4132ea34df",
    0,
    ["*"],
    false
);
console("Runs to polyfs")
// Create empty feat variable
var feat;
console("Runs to feat")
// Populate Feature Array
var tableID = $feature["FeatureID"];
console("Runs to tableID")

 

CarmelConnolly_0-1686063112072.png

This will help narrow down where the issue lies. 

 

 

0 Kudos
Sergio
by
Emerging Contributor

Hi @CarmelConnolly ,

I'm on Enterprise 10.8.1 and it seems like this is  the cause of the issue because I could run this Arcade in AGOL. 

I use the same datasets as in examples and "HydroID" is an integer type, but thanks for clarifying this important nuance. The only difference is that I don't call these layers from original source - I've made a copy for testing purposes and all layers are on the same web map.

Also, I could run this code only in test mode in Arcade editor, but when I tried to display result of this expression in popup it shows no data. And in editor when I click TEST it takes a while till something renders in results window. This lead me to another question - is this a proper way to do this at all? I mean in terms of performance on larger datasets it will work very slow, I presume. is this correct?

One more thing  I've noticed - this expression works like a standard join and shows ALL matched records in result table, but I was hoping that it will show only the data related to the particular polygon. Here is what I see in results:

Sergio_0-1686112949456.png

And here is my exact code that returns above results:

var polyfs = FeatureSetByName($map,"FC_polyfs")
 
var tablefs = FeatureSetByName($map,"T_tablefs - T_tablefs")
 
// 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"],
            }
        }
 
    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" },
    ],
    'geometryType': '',
    'features':features
};
 
// Return dictionary cast as a feature set 
return FeatureSet(Text(joinedDict));

 

Is there a way to implement this as one to many on 10.8.1 where one polygon renders multiple records in popup from separate standalone related to this particular polygon by one particular key field?

Thank you very much for your help and knowledge sharing!

0 Kudos