attribute rule attachment table: expected attachment type arcade error

232
1
01-15-2024 07:29 AM
Labels (1)
geopamplona
New Contributor III

Hi

I am using arcade code to count attachments and save in field, but

Count(Attachments(item));

but I get the following error:
invalid arcade expression, arcade error: expected attachment type, script line: 4geopamplona_0-1705332358982.png

I'm using ArCGIS pro 2.9.11 and enterprise 2.9.1

My attribute rule:

var features = FeatureSetByName($datastore,'FeatureClass', ['*'], false);
var gid=$feature.REL_GLOBALID;
var item=First(Filter(features, 'globalid = @gid'));
var count = Count(Attachments(item));
if ($editcontext.editType == 'DELETE'){
var count_total=count-1
} else {
var count_total=count
}

return {
'edit': [{
'classname' : 'FeatureClass',
'updates' : [{
'globalid': gid,
'attributes' : {'Adjs' :count_total }
}]
}]
}

I have tried the same Count(Attachments()) line and it is valid arcade for calculated fields.

Thanks!

0 Kudos
1 Reply
CodyPatterson
Occasional Contributor III

Hey @geopamplona 

I found a post from a while back that somewhat matches what you have: https://community.esri.com/t5/arcgis-online-questions/arcade-count-attachments-in-related-table/td-p...

I was curious if you could try to do:

    var features = FeatureSetByName($datastore,'FeatureClass', ['*'], false);
    var gid=$feature.REL_GLOBALID;
    var item=First(Filter(features, 'globalid = @gid'));
    var cnt = 0
    for(var item in features) {
        cnt += Count(Attachments(item))
    }
    if ($editcontext.editType == 'DELETE'){
    var count_total=cnt-1
    } else {
    var count_total=cnt
    }

    return {
    'edit': [{
    'classname' : 'FeatureClass',
    'updates' : [{
    'globalid': gid,
    'attributes' : {'Adjs' :count_total }
    }]
    }]
    }

 

This is just a rough rendition so I hope it can provide some help!

 

Cody

0 Kudos