I am trying to apply an attribute rule that would update the parent table of two related tables when the child table is edited. In this case I only want to write the number of related records into the parent table but I am getting this error:
Initiall the field I am trying to write to was of the type short, now I created fields in long, float and double format but none of them are accepted. How can I find out which field type would be supported for my script?
Can you post your script? It would be helpful to see what it's returning
Here it is, with bpmis_data being the child table and bpmis_distinct the parent table:
var select="upi='"+$feature["upi"] +"'";
var fs = FeatureSetbyName($datastore, "bpmis.sde.bpmis_data")
var upi_filtered=Filter(fs,select);
var cnt=Count(upi_filtered)
if (cnt>0){
return {
"result": cnt,
"edit": [
{
"className":"bpmis.sde.bpmis_distinct",
"updates":[
{
"upi": $feature["upi"],
"attributes": {
"permits_cnt": cnt
}
}
]
}
]
}
}
When I try it in the popup I get the expected result ("permits_cnt":14 (number obviously depending on the feature)), but I have to admit that I did not understand yet what the "result" is supposed to do, maybe that's my problem.
Thanks for looking into it!
I'm not an expert on attribute rules, but from the documentation, it looks like you're missing the required object ID or global ID parameter in the updates object
Update:
var select="upi='"+$feature["upi"] +"'";
var fs = FeatureSetbyName($datastore, "bpmis.sde.bpmis_data");
var parent=FeatureSetbyName($datastore, "bpmis.sde.bpmis_distinct",["globalid"],false);
var upi_filtered=Filter(fs,select);
var parent_filtered=Filter(parent,select);
for (var id in parent_filtered){
var parentid=id.globalid;
}
var cnt=Count(upi_filtered)
if (cnt>0){
return {
"edit": [
{
"className":"bpmis.sde.bpmis_distinct",
"updates":[
{
"globalid": parentid,
"attributes": {
"permit_cnt": cnt
}
}
]
}
]
}
}
I am getting closer... At least I don't get an error message any longer but the number is always +1 to what it should be.
Only returning cnt in the popup still gives the correct value. No idea why it would return value+1 when updating the parent table 😞