I am new to Arcade and attribute rules. I am trying to update on table and have it update anothertable. I am using the example here:
An Attribute Rule to keep two geodatabase tables in sync
My test SDE database is named BaseData. In there is a Feature Dataset named BaseData.DBO.InVision. There are two layers one is BaseData.DBO.Building and the other is BaseData.DBO.BuildingFloor. They both share a unique ID called BUILDINGKEY. I am trying to sync the attribute Description. here is my Arcade code:
if ($editContext.editType == "UPDATE") {
//we are updating the row, in this table, so we need to get the corrsponding row in the second table and update it.
var id = $feature.BUILDINGKEY;
var fs = FeatureSetByName($datastore, "BaseData.DBO.BuildingFloor");
var destinationRow = first(Filter(fs, "id = @ID"));
//this should not happen but catching it just in case
if (destinationRow == null) return { "errorMessage": "table out of sync!, we tried to update a row that doesn't exist in the other table.. something is wrong." }
//we can relax that and create the row instead to sync it .
//we need to prevent the update if all fields are the same (otherwise we will be in an infinite cycle
if (destinationRow.DESCRIPTION == $feature.DESCRIPTION) return; //no change quit
//else lets sync them!
return {
"edit": [
{
"className": "BaseData.DBO.BuildingFloor",
"updates": [{
"globalID": destinationRow.globalId,
"attributes": {
"DESCRIPTION": $feature.DESCRIPTION
}
}]
}]
}
}
I get this error when i try and update:
Update table row failed.
Failed to evaluate Arcade expression. [
Rule name: ADA_Update,
Triggering event: Update,
Class name: BaseData.DBO.Building,
GlobalID: {E1222E13-8220-4987-A30A-5186B0E09C10},
Arcade error: Field not found id,
Script line: 5]
If anyone has any ideas i would appreciate the help. thank you.
Solved! Go to Solution.
If they both have the unique ID in the field BUILDINGKEY, then line 5 should be
var destinationRow = first(Filter(fs, "BUILDINGKEY = @ID"));
If they both have the unique ID in the field BUILDINGKEY, then line 5 should be
var destinationRow = first(Filter(fs, "BUILDINGKEY = @ID"));
Ken,
Thanks for your help. I am now getting a new error.
Update table row failed.
Required keyword is not defined in the dictionary return script. [
Rule name: ADA_Update,
Triggering event: Update,
Class name: BaseData.DBO.Building,
GlobalID: {E1222E13-8220-4987-A30A-5186B0E09C10}]Required keyword is not defined in the dictionary return script. [Missing keyword 'objectID or globalID' in the 'updates' array or dictionary.]
Ken
How do i get it to work on 1 to many records. Ex 1 building to many floors?
Ken,
I got it to work. For some reason i had a globalId that wasnt the officail globalID. So i fixed that.The next question is. The Building layer is related to the floor layer where i am puching the changes. When i edit it updates one row only. For example, the Geology building has four floors nad it update the 1st record for the Geology floors but not the otehr three. Do i have to create some sort of array?