Calculate Field from related table

942
4
02-16-2023 01:28 PM
janderson_ksninc
Occasional Contributor

I have a table of points from field observations and a related table holding the pictures for each point. I need to rename the photos after the ID of the point. I would like to take the value from the ID field of the points and use it to replace the attachment name, then concatenate a ".jpg" and the end of the string. Is there an Arcade Expression that does this?

0 Kudos
4 Replies
RhettZufelt
MVP Notable Contributor

Not sure of a way in Arcade, but very doable in python.

I use this on feature class with attachments enabled to update the attachment name to the id of the point (My attachments are all jpegs).

 

import arcpy

inFeatureClass = r'Database Connections\dbname.sde\dbname.DBO.Points'         # feature class with attachments
pointFieldsList = ['GlobalID','ID']                                           # fields to load into cursor

inTable = r'Database Connections\dbname.sde\dbname.DBO.Points__ATTACH'        #  attachment table for feature class
tableFieldsList = ['REL_GLOBALID', 'DATA', 'ATT_NAME', 'ATTACHMENTID']        # field list in attachment table   


global_dict = {}

with arcpy.da.SearchCursor(inFeatureClass, pointFieldsList) as point_cursor:  # cursor to make dict of globalID's
        for row in point_cursor:
          if row[1]:
            row1 = row[1]                                 # I'm using "ID" as my name field, but is
          else:                                           # not always populated.  if Null, substitute "NA"
            row1 = "NA"
          global_dict[row[0]] = row1                      # add to dict with globallID as key, name as value



with arcpy.da.UpdateCursor(inTable, tableFieldsList) as cursor:

    for row in cursor:
        if row[0] in global_dict:
            row[2] = global_dict[row[0]] + '.jpg'
            cursor.updateRow(row)

 

R_

0 Kudos
JohannesLindner
MVP Frequent Contributor

For the Calculate Field tool with Arcade:

var related = First(FeaturesetByRelationshipName($feature, "TestPoints__ATTACHREL"))
if(related == null) { return $feature.ATT_NAME }
return related.OBJECTID + ".jpg"

 

Before:

JohannesLindner_0-1676619213668.png

 

After:

JohannesLindner_1-1676619409289.png

 


Have a great day!
Johannes
0 Kudos
janderson_ksninc
Occasional Contributor

Thanks for responding! Would you happen to know how to do this in an Arcade Expression for an indicator in Dashboards?

0 Kudos
JohannesLindner
MVP Frequent Contributor

What do you want to show in the indicator?


Have a great day!
Johannes
0 Kudos