Arcade - Update Feature Class based on related table

4251
14
07-23-2020 01:48 PM
KierenTinning2
New Contributor III

All,

I am trying to implement an attribute rule which updates a feature class field when the related 1:M table gets updated.  The process right now is, the field in the related table changes, we get the keys, roll up the data into a string and then get the related record in the feature class and write the text value.

Issue is, a) the for loop is in error and if I comment it our and put a dummy value in my text variable, it doesn't actually write anything.

Any help would be appreciated.- thank you

var tbl = FeatureSetByName($datastore,"DB.LAND.CustomerAddress");
var fc = FeatureSetByName($datastore,"DB.LAND.AddressLocation");
var locationeguidKey = $feature["locationeguid"];
var CustomerSql = "locationeguidKey = '" + locationeguidKey + "'";
var premiseSQL = "GlobalID = '" + locationeguidKey + "'";
var CustomerAddressResult = Filter(tbl, CustomerSql);
var txt = null;

var address;

for (var address in nonCustomerAddressResult){
txt = Text(address.building_number, ',');
}

return {

if (Count(txt) > 0){
txt = Left(txt, Count(txt) - 1);
premiseResult = Filter(fc, premiseSQL)
// premiseKey.labeltext = txt;
}

"result" : txt,

"edit":[{
"className": "premiseResult",
"updates" : [{
"labeltext": txt
}]
}]
}

14 Replies
KierenTinning2
New Contributor III

Xander Bakker‌ what needs to happen is

Premise has label field - records to label from come from related customer table (1:M relationship class).  As the label profile for Arcade doesn't support relationship classes, we roll up the address information from the customer table and write the building numbers to a string which is then written to the label field on the feature class.  A complicated label script then runs and voila, all is well.

If we add a related record and then add a building number, the rule runs and rolls everything up.  If we modify the customer record then the script runs and updates the label field. 

The problem, if I remove a related record from the customer table the script crashes on a keyword error.  If I delete a related record in the customer table the script doesn't run, thereby leaving the label field in an incorrect state.  If I update an address it's fine.  

Key is deleting a customer record (table) doesn't cause the Update to happen.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi KierenTinning ,

Thanks for the clarification. Have you looked at "Message notification direction" in Relationship class properties—Relationships and related objects | Documentation ? It may provide what you need by deleting related records when the parent is deleted. 

0 Kudos
KierenTinning2
New Contributor III

Xander Bakker‌ thank you for the idea.  In this case though, I need to update a record in the parent when the child is deleted, I am not actually triggering deletes..

Example, ParentID 54 has children A, B and C  - each child has an address record.  Due to a limitation in the Arcade labeling profile, the script reads the building number from the children and writes the building numbers to the Parent as a comma separated list in a "label" field - which a labeling Arcade script processes.

If we add Child D - it's building number when created triggers the update and the building number is written to Parent 54, so it now has building numbers from child A, B, C and D. 

The problem is, if we delete child C - then the Arcade script never runs, so the Parent has building numbers from Child A, B, C and D.  If we modify a building number in child A for example, then the script runs and updated the parent removing the building number from child C.  So my problem that I am working on, is if Child C is deleted, how do I trigger an update such that the Parent will only have building numbers from A,B and D

Thanks for the help.

Kieren

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Kieren Tinning ,

Thanks for the additional explanation. What you want to do is configure an attribute rule on the address table that is triggered by insert, update and delete. This way you can use the new situation to modify the building numbers on the other featureclass.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Kieren Tinning ,

Would I still use $map in the attribute rule?

No, $map is not available for attribute rules. They are executed at the database level and at that level there is no knowledge about any map. I also recommend using the $datastore in the pop-up to be closer to the actual situation you want to solve.

Also, the $feature here is referencing the point I clicked, however in the attribute rule it's actually reversed as it would be from the table to the feature?

That changes things a bit. You will have to use a default value for the table record to simulate the process. Instead of using

var locationeguidKey = $feature["locationeguid"];

You should assign an existing "loctioneguid"  value from your table to ensure that you can simulate the process.

As for the SQL, I am using it as I need to roll up all of the values from the table and then write them to the the feature in a comma separated list.

The SQL will not work the way you configured it. Verify if you can use FeatureSetByRelationshipName function and if not, change the sql using the example I provided before. Either use this:

var nonCustomerSql = "premiseguid = @premiseKey";
var premiseSQL = "GlobalID = @premiseKey";

... or:

var nonCustomerSql = "premiseguid = '{" + Upper(premiseKey) + "}'";
var premiseSQL = "GlobalID = '{" + Upper(premiseKey) + "}'";

The following line will not work:

txt = txt + Text(address.building_number, ',');

If the building number is numeric then you will have to use the Text function to convert it to text (applying any formatting you want) and concatenate it with the comma. 

txt = txt + Text(address.building_number) + ',';

 

The line:

premiseKey.labeltext = txt;

... will result in an error, since premiseKey is a GlobalID and does not have a property "labeltext". 

0 Kudos