I'm trying to build a script to create a joined layer based on a feature layer and a table my client gave me with only data entry permissions. The structure of the two layers is something as following (just an extraction of the key fields):
As you can see, between the two layers there are two matching field and both are string fields. The Object ID for the first layer is set by design, while the second Object ID is generated after the table gets populated with the data from a Survey123 form.
I have found a script on github that allows to join two layers (a layer and a table) through a matching field and I've tested as it is on AGOL and it is working.
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));
I presume the functioning of this script is that the matching field is FeatureID in the table layer and HydroID in the feature layer. By doing so you can then set variables calling fields from both the source layers.
I have then started to adapt everything to the layers and specifics I have, but when I modified the matching references from var tableID = t["FeatureID"]
to var tableID = t["parentGUID"]
(the foreign key in the table layer) I got this error:
Test execution error: Expected ".", [0-9], or [eE] but "c" found.. Verify test data.
At first I had no clue, but with some trials I'm suspecting this method wants an integer field type as matching field, but in my case I have a string field type and the ObjectID field is referring to different things.
Is there another way to perform this join using string field type as matching field?