Attribute Rule - Calculation Type - Not working

272
4
Jump to solution
10-29-2021 02:15 PM
Labels (1)
Raj-Chavada
New Contributor III

Hello,

We have two feature classes A & B in enterprise geodatabase environment. They are participating in a relationship class.

A - Projects

B- Sewer upgrades

Our goal/requirement is to automatically update the common attributes on existing features in B if the same attribute fields are updates in A. 

To accomplish this, base on the example available here, I came up with following (immediate calculation rule on A):

 

//s1 - get all the features from sewer upgrades feature class
var destination = FeatureSetByName($datastore, "GEO_DB.ENG_SD.SewerUpgrade", ["DBNUMBER","TECH_REV", "CONS_ST", "CONS_ED", "EST_CON_DUR", "STATUS"], false);

//s2 - get dbnumber edited in the projects developments feature class
var dbnumber = $feature.DBNUMBER;

//s3 - filter feature based on the existing edit 
var match = Filter(destination, "DBNUMBER = @dbnumber");

//s4 - update records in sewer upgrades
var sewerupgradelist = [];
var counter = 0;
var numfeatures = Count(match);

if (numfeatures > 0) {
    for (var feature in match)  {
           sewerupgradelist[counter] = {
                'OBJECTID' : feature.OBJECTID,
                'attributes' : {
                         'CONS_ST' : $feature.CONS_ST,
                         'CONS_ED' : $feature.CONS_ED,
                     'EST_CON_DUR' : $feature.EST_CONS_DUR,
                        'TECH_REV' : $feature.TECH_REV,
                          'STATUS' : $feature.STATUS 
                        }
                     }
                     counter++
                  }
                  return {
                         'result' : numfeatures + ' sewer upgrades features found.',
                          'edit' : [{
                               'className' :  "GEO_DB.ENG_SD.SewerUpgrade",
                                'updates' :   sewerupgradelist
                             }]
                      }
                   

  }else {
    return 'No features found under sewer upgrade with matching DBNUMBER.'
  }

 

 

While there are no validation errors, ArcGIS Pro comes up with following error during testing:

 

RajChavada_0-1635542042816.png

 

Any help in resolving the issue will be appreciated. 

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
Regular Contributor

According to the documentation of the attribute rule dicitonary keywords ,

  • the "result" field in the returned dictionary is either
    • a value for the field definied as return field for the rule
    • a dicitionary for the geometry and/or attributes of the feature, if you haven't set a return field in the rule
  • You return a log message. If you haven't set a text field as output field of the rule, this should throw an error.
  • The ObjectID in the update array should be given in the dictionary field "objectID", not "OBJECTID", don't know if this would cause an error, though.

 

So, try this:

//s1 - get all the features from sewer upgrades feature class
// you only need DBNUMBER (to filter) and OBJECTID (to send edits)
var destination = FeatureSetByName($datastore, "GEO_DB.ENG_SD.SewerUpgrade", ["DBNUMBER","OBJECTID"], false);

//s2 - get dbnumber edited in the projects developments feature class
var dbnumber = $feature.DBNUMBER;

//s3 - filter feature based on the existing edit 
var match = Filter(destination, "DBNUMBER = @dbnumber");

//s4 - update records in sewer upgrades
var sewerupgradelist = [];
var counter = 0;

for (var feature in match)  {
    sewerupgradelist[counter] = {
        'objectID' : feature.OBJECTID,
        'attributes' : {
            'CONS_ST' : $feature.CONS_ST,
            'CONS_ED' : $feature.CONS_ED,
            'EST_CON_DUR' : $feature.EST_CONS_DUR,
            'TECH_REV' : $feature.TECH_REV,
            'STATUS' : $feature.STATUS 
        }
    }
    counter++
}
return {
// only use this if you have set a text field as return field for the rule
//    'result' : numfeatures + ' sewer upgrades features found.',
    'edit' : [{
        'className' :  "GEO_DB.ENG_SD.SewerUpgrade",
        'updates' :   sewerupgradelist
    }]
}

 

 


Have a great day!
Johannes

View solution in original post

4 Replies
Mike_I
by Esri Contributor
Esri Contributor

Hello Raj-Chavada,

I'm not sure this is the reason for the error message, but I see something I'd like to ask about:

At Line 2, in your field list, I see 6 fields: "DBNUMBER", "TECH_REV", "CONS_ST", "CONS_ED, "EST_CON_DUR", and "STATUS"

In Lines 20-25, I see 6 fields: 'CONS_ST', 'CONS_ED', 'CONS_ST', 'EST_CON_DUR', 'TECH_REC', and 'STATUS'

  • In these lines of code, 'CONS_ST' is referenced 2x while 'DBNUMBER' is not referenced.
  • Is this by design?
  • Is it possible 'DBNUMBER' is meant to be referenced, but the 2x 'CONT_ST' is causing confusion, and that is the reason for the error?

What do you think?

Regards,

Mike

 

Data Management Specialist, Esri Support Services
0 Kudos
Raj-Chavada
New Contributor III

Thanks, Mike! Please see my reply below:

  • In these lines of code, 'CONS_ST' is referenced 2x while 'DBNUMBER' is not referenced. Is this by design?

RC: No. This is an error on my part. Removed the extra line.

  • Is it possible 'DBNUMBER' is meant to be referenced, but the 2x 'CONT_ST' is causing confusion, and that is the reason for the error?

RC: I am not referencing 'DBNUMBER' because that attribute field not required to be updated. 

0 Kudos
JohannesLindner
Regular Contributor

According to the documentation of the attribute rule dicitonary keywords ,

  • the "result" field in the returned dictionary is either
    • a value for the field definied as return field for the rule
    • a dicitionary for the geometry and/or attributes of the feature, if you haven't set a return field in the rule
  • You return a log message. If you haven't set a text field as output field of the rule, this should throw an error.
  • The ObjectID in the update array should be given in the dictionary field "objectID", not "OBJECTID", don't know if this would cause an error, though.

 

So, try this:

//s1 - get all the features from sewer upgrades feature class
// you only need DBNUMBER (to filter) and OBJECTID (to send edits)
var destination = FeatureSetByName($datastore, "GEO_DB.ENG_SD.SewerUpgrade", ["DBNUMBER","OBJECTID"], false);

//s2 - get dbnumber edited in the projects developments feature class
var dbnumber = $feature.DBNUMBER;

//s3 - filter feature based on the existing edit 
var match = Filter(destination, "DBNUMBER = @dbnumber");

//s4 - update records in sewer upgrades
var sewerupgradelist = [];
var counter = 0;

for (var feature in match)  {
    sewerupgradelist[counter] = {
        'objectID' : feature.OBJECTID,
        'attributes' : {
            'CONS_ST' : $feature.CONS_ST,
            'CONS_ED' : $feature.CONS_ED,
            'EST_CON_DUR' : $feature.EST_CONS_DUR,
            'TECH_REV' : $feature.TECH_REV,
            'STATUS' : $feature.STATUS 
        }
    }
    counter++
}
return {
// only use this if you have set a text field as return field for the rule
//    'result' : numfeatures + ' sewer upgrades features found.',
    'edit' : [{
        'className' :  "GEO_DB.ENG_SD.SewerUpgrade",
        'updates' :   sewerupgradelist
    }]
}

 

 


Have a great day!
Johannes

View solution in original post

Raj-Chavada
New Contributor III

Thank you so much! This worked. Accepting as solution. 

0 Kudos