Field value not preserved when Attribute Insert Rule active

161
2
Jump to solution
06-01-2020 01:25 PM
New Contributor III

I have an Attribute Rule set to trigger on Insert (using ArcGIS Pro 2.5.1).  It takes the value of a field in a source layer and then adds it to the field in a target layer.  It works so far that the target table gets updated. However, after insert the source field resets back to it's default of 0 (it's a number field).

When I deactive the rule the source layer gets updated normally.

Both layers are tables in a FGDB.  The target table only has one row.

var fsTargetTable = First(FeatureSetByName($datastore, "Totals", ["globalid","gloves_xs"], false));

var glovecount = $feature.gloves_xs;
var totalglovecount = fsTargetTable.gloves_xs;
totalglovecount += glovecount;
var AddList = [];
AddList[0] = {
'globalid':fsTargetTable.globalid,
'attributes':{
'gloves_xs':totalglovecount
}
};
return {
'edit': [{
'className': 'Totals',
'updates': AddList
}]
}

1 Solution

Accepted Solutions
Esri Contributor

Hello!

Hope I can help, the reason the value is getting set to 0 is because you haven't provided a result in the return payload. thus the default will be used..

If you want to preserve the field value you input just simply return it back as follows..

 

var fsTargetTable = First(FeatureSetByName($datastore, "Totals", ["globalid","gloves_xs"], false));
var glovecount = $feature.gloves_xs;
var totalglovecount = fsTargetTable.gloves_xs;
totalglovecount += glovecount;
var AddList = [];
AddList[0] = {
'globalid':fsTargetTable.globalid,
'attributes':{
'gloves_xs':totalglovecount
}
};
return {
'result': $feature.yoursourcefieldname,
'edit': [{
'className': 'Totals',
'updates': AddList
}]
}

View solution in original post

2 Replies
Esri Contributor

Hello!

Hope I can help, the reason the value is getting set to 0 is because you haven't provided a result in the return payload. thus the default will be used..

If you want to preserve the field value you input just simply return it back as follows..

 

var fsTargetTable = First(FeatureSetByName($datastore, "Totals", ["globalid","gloves_xs"], false));
var glovecount = $feature.gloves_xs;
var totalglovecount = fsTargetTable.gloves_xs;
totalglovecount += glovecount;
var AddList = [];
AddList[0] = {
'globalid':fsTargetTable.globalid,
'attributes':{
'gloves_xs':totalglovecount
}
};
return {
'result': $feature.yoursourcefieldname,
'edit': [{
'className': 'Totals',
'updates': AddList
}]
}

View solution in original post

New Contributor III

Thanks for the reply! This was my issue and the rule works great now.

Reply
0 Kudos