Attribute Rule: Is it possible to get attachment filename for record in a related table

591
7
04-28-2020 12:46 PM
LyndaUrtheil
New Contributor

First post:  I have a feature class for support poles, created in ArcGIS Pro, I have a related (non-spatial) table for sign information and this has attachments enabled.  In Collector (Windows) I am able to add a support pole and then add a sign, including adding a file attachment selected from a network drive.  I can add several signs, with attachments and all works well.  I would like to add the name of the attached file, into a field in my related signs table.  I'm new to Arcade and can't figure out the syntax for getting this accomplished. Or maybe what I'm trying to do is not possible ....

I've been able to fill a field in the sign detail table from a record in the originating fc Poles with the following:

Field to update:  WorkYard field in the sign details table

......

var tbl = FeatureSetByName($datastore,"SupportPole");
var PoleID = $feature["signSupport_ID_FK"];
var sql = "signSupportID = '" + PoleID + "'";
var Details = Filter(tbl, sql);
var cnt = Count(Details);
var WorkYardVal = "";
if (cnt > 0) {
for (var Detail in Details) {
var WorkYardVal = Detail.WorkYard;
}
}

return WorkYardVal;

.......

and I've been trying to get the following code I found online to work, but to no avail 

(I recognize that the $feature is referring to the original point selected which is the Poles feature class, but how do I reach a table that is an attachment table to a related table???

...

var attachmentOptions = {"types":["image/jpeg"]}
var jpgAttachments = Attachments($feature,attachmentOptions)
var jpgName

// Make sure there are attachments before trying to get the properties
If (!isEmpty(jpgAttachments)) {
for (var a in jpgAttachments) {
//look for the specific file name
jpgName = jpgAttachments.name
}
} else {
jpgName = "None";
}

return jpgName;

...

Version of ArcGIS Enterprise:10.7.1
Is your Portal and Server federated:Yes.
Is your deployment setup on a single machine:it’s on multiple machines.
Is your published data hosted;No, it’s referenced in an enterprise geodatabase/SQL Server 2017.

Any assistance would be greatly appreciated.

Thanks.

0 Kudos
7 Replies
XanderBakker
Esri Esteemed Contributor

Hi Lynda Urtheil ,

That is a complicated questions and more complex to replicate and test. 

I do think it might be possible to do what you are after. Your Enterprise 10.7.1 has Arcade version 1.7 and the Attachments function is available as from version 1.6 of Arcade in the Attribute Rules. 

The attachments function will require a feature and your question is about how to get that. Since I am not able to replicate your situation let me try to explain with another example what I would try in your case.  In the sample below I have a filter set up to query features in this case from the same layer, but this could be your related table. It will return a featureset and to get to the first record I will use the First function. Now I have a feature (record of the table) and I am able to use that feature to get the related records (this could be used I think to get to the related attachments):

var sql = "AcctNo = 608";
var fs = Filter($layer, sql);
Console(fs);
var f = First(fs);
Console(TypeOf(f));
Console(f);
var fsrel = FeatureSetByRelationshipName(f,"RelData");
Console(fsrel);
var frel = First(fsrel);
Console(TypeOf(frel));
Console(frel);

This will return:

object, FeatureSet
Feature
{"geometry":{"x":-8412482.557699999,"y":693242.5571999997,"spatialReference":{"latestWkid":3857,"wkid":102100}},"attributes":{"OBJECTID":3,"AcctNo":608}}
object, FeatureSet
Feature
{"geometry":null,"attributes":{"OBJECTID":5,"AcctNo":608,"ProjectPhase":"Planning","DateModified":1522540800000}}
0 Kudos
LyndaUrtheil
New Contributor

Hi Xander,

I’ve tried your suggested code, made the appropriate name changes but I get an error - Object not found $layer

I’ll have to play around with it later, I have to move on and get a few other things done today.

I do have another quick question though.

Where does console show up, how do I view the results?

Lynda Urtheil

• 905-615-3200 ext.5814

lynda.urtheil@mississauga.ca<mailto:lynda.urtheil@mississauga.ca>

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Lynda Urtheil ,

I'm sorry, I guess my previous post was not very clear. I will see if I can adjust your code with what I am thinking that could be a possible solution and post that back when I have some more time. 

About the Console, when you test your code the result will be presented, but there is also a tap for "Messages":

That is where the console messages will be listed:

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi lynda.urtheil@mississauga.ca ,

I was more thinking about something along the lines like this:

// you have a feature and you will retrieve the related record
var relateddata = FeatureSetByRelationshipName($feature, "TheNameOfYourRelationshipGoesHere");

// test if you have related records
var cnt1 = Count(relateddata);
if (cnt1 > 0) {
    // you have related records, take the first record
    var relatedrec = First(relateddata);

    // try and get to the attachments of the related record
    var attachmentOptions = {"types":["image/jpeg"]};

    // here you will use the related record to see if this works
    var jpgAttachments = Attachments(relatedrec, attachmentOptions);
    
    // next check if you got any attachments
    var jpgName = "";
    If (!isEmpty(jpgAttachments)) {
        // you have a list of attachments with at least 1 item
        for (var a in jpgAttachments) {
            //get the list of filename
            if (jpgName == "") {
                // first jpg name
                jpgName = jpgAttachments[a].name;
            } else {
                // all other jpg names, this may create a long string 
                // and overflow the length of the field
                // if you only need one, use First(jpgAttachments).name
                jpgName += ", " + jpgAttachments[a].name;
            }
        }
    } else {
        jpgName = "No Attachments";
    }
}

return jpgName;
0 Kudos
LyndaUrtheil
New Contributor

Thanks again Xander,

I will give your suggested code, for getting the attach name, a try as soon as I can.

On the Arcade console question, I’m off in left field LOL. I need to clarify that I’m working in ArcGIS Pro and creating an Attribute rule, the only option I see for creating an expression is using Arcade (no Python option) and I want to view the results of the console call. I’m just getting acquainted with ArcGIS Pro, I’m working in the Expression Builder and all I see is a green check to verify that the code is valid. No where to select Results or Messages, I think I’m looking in the wrong area.

Is there another way to create and verify your code for an attribute rule that I’m missing?

Lynda Urtheil

• 905-615-3200 ext.5814

lynda.urtheil@mississauga.ca<mailto:lynda.urtheil@mississauga.ca>

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Lynda Urtheil ,

That makes sense. Sorry for providing info based on AGOL/Enterprise when you are using the ArcGIS Pro attribute rule editor.  Although "Console" is valid and can be used in the Attribute Rule editor in ArcGIS Pro, I have no idea where you would be able to consult the output.

I would try and test the code on your data and if it returns any errors please share them here to see if they can be solved. 

0 Kudos
by Anonymous User
Not applicable

I realize this is an older thread but I'll throw in my work around. I have been copying code from constraint attribute rules to a calculation attribute rule and then output what would have gone to the console to a notes field. This at least gives me an idea of what might be going wrong in the constraint rule. You might have to concatenate several console messages to put it all in the notes field. It's ugly but seems to work. It would be great if it was possible to view console output when an attribute rule runs. Particularly when an attribute rule doesn't work as expected.

0 Kudos