Select to view content in your preferred language

ArcGIS Pro - AttributeRule - Trigger - Should trigger only for update on one specific column

657
3
Jump to solution
03-07-2023 12:54 AM
Vara_PrasadM_S
Occasional Contributor II

Hi Team,

I am using ArcGIS Pro V 3.0.3. I am planning to add an Attribute Rule on Feature Class - B to copy value from Field1 of Feature Class - A, based on value from Field2 of Feature Class B.

I would like to add Attribute Rule for Insert trigger only, however, by that time, Feature Class B's new feature may not have value for Field2. So, have to include Update trigger also. 

In this scenario, how can we control execution of Attribute Rule only on update of Field2 value of Feature class B and not on any kind of Update.

Thanks in advance!

With Regards,

Vara Prasad

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

 

// Calculation Attribute Rule on Featureclass B
// Field1
// Triggers: Insert, Update

var field_2 = $feature.Field2

// if we're inserting a fetaure with an empty Field2
// or we're updating a feature without changing Field2,
// return the value that is already in Field1
if(($editcontext.editType == "INSERT" && field_2 == null) ||
   ($editcontext.editType == "UPDATE" && $originalfeature.Field2 == field_2)) {
    return $feature.Field1
}

// load Featureclass A
var fc_a = FeaturesetByName($datastore, "FeatureclassA")
// get the related feature
var related_a = First(Filter(fc_a, "Field2 = @field_2"))
// return that feature's Field1 value or null if no feature was found
return IIf(related_a == null, null, related_a.Field1)

 


Have a great day!
Johannes

View solution in original post

3 Replies
JohannesLindner
MVP Frequent Contributor

 

// Calculation Attribute Rule on Featureclass B
// Field1
// Triggers: Insert, Update

var field_2 = $feature.Field2

// if we're inserting a fetaure with an empty Field2
// or we're updating a feature without changing Field2,
// return the value that is already in Field1
if(($editcontext.editType == "INSERT" && field_2 == null) ||
   ($editcontext.editType == "UPDATE" && $originalfeature.Field2 == field_2)) {
    return $feature.Field1
}

// load Featureclass A
var fc_a = FeaturesetByName($datastore, "FeatureclassA")
// get the related feature
var related_a = First(Filter(fc_a, "Field2 = @field_2"))
// return that feature's Field1 value or null if no feature was found
return IIf(related_a == null, null, related_a.Field1)

 


Have a great day!
Johannes
Vara_PrasadM_S
Occasional Contributor II

Hi @JohannesLindner ,

Thank you very much for the inputs. It is almost same as that of my code except using editcontext. I learnt a new point - editcontext from your post. Thank you.

FeatureclassByName- is not available it seems. "Verify" option is throwing error. I have used FeatureSetByName function. Apart from that rest of the code is working fine. Thank you very much.

With Regards,

Vara Prasad

0 Kudos
JohannesLindner
MVP Frequent Contributor

FeatureclassByName- is not available

Oops, got confused with the terminology. Good catch, I edited my answer.


Have a great day!
Johannes