Is Arcade Attachments() supported with a protected service
I'm trying to display an attachment in a feature's popup, but I can't seem to get it working. Even a script as simple as Count(Attachments($feature)) does not work; it always returns '0'.
In the browser's developer tools, I don't see any request to the queryAttachments endpoint either.
Could the problem be that the service is protected?
-
Yes, it works with protected service. Make sure your service is a Feature Service and not a Map Service. I also think the related table need to be included in the Feature Service. I used the following to get at the attachments. It is almost a carbon copy of an Esri (or Geocortex) example. I will try to find the link.
function makeAttachmentLink(name, id, oid, url) {
return '<' + 'a ' + 'href="' + url + '/' + oid + '/attachments/' + id + '" target="_blank">' + name + '<' + '/' + 'a>';
}
function makeAttachmentLinks(serviceUrl, oidField) {
if (IsEmpty(oidField)) {
oidField = "OBJECTID";
}
var a = Attachments($feature);
var result = "";
//var years = [];
var maxYear = 0;
var curYear = 0;
//find max year
for (var i in a) {
curYear = Number(Left(a[i].name,4));
if (curYear > maxYear){
}
//years[i] = Left(a[i].name,4);
}
//add links for max year attachments
for (var i in a) {
curYear = Number(Left(a[i].name,4));
if (curYear == maxYear){
result += makeAttachmentLink(a[i].name, a[i].id, $feature[oidField], serviceUrl) + TextFormatting.NewLine;
}
}
if (IsEmpty(result)) {
result = "None"
}
return result;
}
makeAttachmentLinks("https://arcgis server service/FeatureServer/0")1 -
Thanks I tried with a FeatureService, which indeed works!
I don't suppose there's a workaround for that?
0 -
No, I do not think so. From what I've seen, you need a Feature Service when using Arcade. Plus some of the functionality is only available when publishing with Pro. I don't recall the exact details but to get Arcade to work as expected I switched from ArcMap to Pro.
0 -
Field operations seem to work, even with mapservices (e.g. $feature.myField * 100). I also can't think of reason why attachments would only work for featureservices, they work the same for both types. But so be it.
0
Please sign in to leave a comment.
Comments
4 comments