Select to view content in your preferred language

Attribute rules on update field: "The field type is not supported by arcade script."

275
5
11-14-2024 06:13 AM
DrNicsi
Emerging Contributor

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: 

DrNicsi_0-1731593259838.png

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?

0 Kudos
5 Replies
KenBuja
MVP Esteemed Contributor

Can you post your script? It would be helpful to see what it's returning

0 Kudos
DrNicsi
Emerging Contributor

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!

0 Kudos
KenBuja
MVP Esteemed Contributor

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

DrNicsi
Emerging Contributor

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.

0 Kudos
DrNicsi
Emerging Contributor

Only returning cnt in the popup still gives the correct value. No idea why it would return value+1 when updating the parent table 😞

0 Kudos