Two questions related to labeling 1:M related records in ArcGIS 10.2.

I have successfully built an Advanced Label expression in Python to label records from a related table. I am currently working from a local file geodatabase as a datasource. I need to migrate my label expression to work with an enterprise geodatabase. Result of the label expression code should be as follows:

 FacilityID  (data from parent table) 
 RatedKVA    (data from parent table)
 EquipID1    (data from related table)
 EquipID2    (data from related table - may not exist)
 EqiupID3    (data from related table - may not exist)


def FindLabel( [GlobalID], [FACILITYID] , [RatedKVA] ):
   strWhereClause = '"TransformerGlobalID" = \'{0}\''.format([GlobalID])
   strpTable = "C:\GIS\ArcFMViewer\Data\ElectricArcFMViewer.gdb\TRANSFORMERUNIT"
   cursor = arcpy.da.SearchCursor(strpTable, "EquipID", strWhereClause)
   result = [FACILITYID] + "\n" + [RatedKVA] + "\n"
   for row in cursor:
        strLabel = str(row[0])
        result += strLabel + "\n"
   return result.rstrip()

Question 1: How do I point the code to find the object table in the SQL Server based geodatabase and not the local?

Question 2: This code works perfectly if there is only one EquipID related record. If there are two or three related EquipID records the feature fails to label. No error or "!", just no label at all. Code will label all related records if I remove the FacilityID and RatedKVA arguments (result = "" in code). I don't understand why this occurs.

Note: I do have a version of this working in VBScript as well if that makes a difference for the data connection to the enterprise geodatabase.


1 Answer 1


Figured it out through VBScript. Will research how to do this in Python now that I have working template...

Function FindLabel ( [gis.GIS.Transformer.GlobalID], [gis.GIS.Transformer.FACILITYID] , [gis.GIS.Transformer.RatedKVA])
Dim objConnection, objRecordset, strSearchCriteria
Const adOpenStatic = 3
Const adLockOptimistic = 3

' Connection string for SQL Server database.
strConnect = "DRIVER=SQL Server;" _
& "Trusted_Connection=Yes;" _
& "DATABASE=dbName;" _
& "SERVER=dbServer"

' Connect to database.
Set adoConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")

adoConnection.ConnectionString = strConnect

Dim strSQLQuery, strWhereClause, strLabel 
strWhereClause = chr(34) & "TransformerGlobalID" & chr(34) & " = '" & [gis.GIS.Transformer.GlobalID] & "'"
strSQLQuery = "SELECT *  FROM gis.GIS.TRANSFORMERUNIT WHERE " & strWhereClause 

Set oRS=CreateObject("ADODB.Recordset")
Set oRS = adoConnection.Execute(strSQLQuery)

while not oRS.eof
 strLabel = strLabel & oRS.Fields("EquipID").value & vbnewline

Set oRS = Nothing
Set adoConnection = Nothing   

FindLabel = [gis.GIS.Transformer.FACILITYID] & vbnewline & [gis.GIS.Transformer.RatedKVA] & " KVA" & vbnewline & strLabel  
End Function


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.