How to change the value of a field in a feature class when inserting a new record in the linked table

476
2
Jump to solution
10-13-2022 07:08 AM
DoucetMarjorie
New Contributor
Hi,
I'm trying to apply an attribute rule on a table (lightingintervention)
linked by a relationship class on a feature class (luminaire). The rule must trigger on the insertion of a new record or on the update and allows you to: When a new intervention is created the value of the "STATUS" field in my
feature class "luminaire" must change. Here is my code:

var relid = $feature.PARENTGUID

var fsrel = FeatureSetByName($datastore, "gocite.GOCITE.Luminaire",["globalid","etat","objectid"],false)

var frel = filter(fsrel,"globalid = @relid")

var rel = first(fsrel)

var BonEtat = 1

var Reparer = 2

 

if(isempty($feature.dateeffectuee)){

    var et = Reparer}

else{

    var et = BonEtat}

 

return {

'edit':[{

    'classname':'gocite.GOCITE.Luminaire',

       'updates':[{

        'globalID':relid,

           'attributes':{

               'Etat':et

            }

        }]

    }]

}

Error message :

DoucetMarjorie_0-1665669513949.png

 

I need help with the error, I can't find how to fix it
Tanks !

 

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
HusseinNasser2
Esri Contributor

Your attribute rule is correct, the problem is the order of operations and how the relationship record is created. This is something we are trying to address. Relationships are created after attribute rules. 

When you add the related record, the related foreign key `.PARENTGUID`  is not populated, so when the insert attribute rule gets triggered, the foreign key .PARENTGUID is null, which of course will fail to find the parent and fail the edit. 

 

Two workarounds, 

you can add the relationship record directly to the table and during that insert fill in the parentGUID , this will cause the Insert trigger to have the parentGuid and the rule should work.

Another workaround is to make the attribute rule on update and tell users to make a physical update to the related record (update a field etc.. ) to force trigger the update attribute rule. 

 

I understand the workarounds might not be ideal, we are working on a solution not sure how long it will take though. 

 

View solution in original post

0 Kudos
2 Replies
HusseinNasser2
Esri Contributor

Your attribute rule is correct, the problem is the order of operations and how the relationship record is created. This is something we are trying to address. Relationships are created after attribute rules. 

When you add the related record, the related foreign key `.PARENTGUID`  is not populated, so when the insert attribute rule gets triggered, the foreign key .PARENTGUID is null, which of course will fail to find the parent and fail the edit. 

 

Two workarounds, 

you can add the relationship record directly to the table and during that insert fill in the parentGUID , this will cause the Insert trigger to have the parentGuid and the rule should work.

Another workaround is to make the attribute rule on update and tell users to make a physical update to the related record (update a field etc.. ) to force trigger the update attribute rule. 

 

I understand the workarounds might not be ideal, we are working on a solution not sure how long it will take though. 

 

0 Kudos
DoucetMarjorie
New Contributor

I created a new attribute rule that sends the GlobalID in the parentguid of the interventions table.

Then I set up the trigger of the attribute rule on update and everything is fine.

Thanks for your help,