For reasons that are too numerable my organization has yet to update our database and sde feature layers to Pro versions. As such we cannot use attribute rules yet. One layer that our editor uses needs to have two fields updated using other fields. Doing it by hand is cumbersome when dealing with 400 plus features. Our work around so far has been to use calculate field tool which works but when the updated values require some high level expressions it can be discouraging. I developed a python script to do this for me and it runs just great for me but my coworkers keep getting the error that only the owner of sde.default can make edits.
I have set it up to use the arcpy.management.ChangeVersion. However, the same error appears even after using this function. Why isn't the version my coworkers are choosing not being used? Secondly I have noticed that if I have a selection in the feature layer once I change the version of the feature layer that selection is no longer valid. shouldn't the selection still be honored? The parameters are all set up through drop down lists and layer lists, so I am pretty confidant that the correct paths and names are being used. I find it strange I can use this script with no errors but others can't, I am not the owner of the sde.default version either.
workspaceName = arcpy.GetParameterAsText(0)
sdeParcel = arcpy.GetParameterAsText(1)
arcpy.AddMessage("parcel layer is {0}".format(sdeParcel))
version = arcpy.GetParameterAsText(2)
aprx = arcpy.mp.ArcGISProject("CURRENT")
arcpy.env.workspace = os.path.join(aprx.homeFolder,workspaceName)
arcpy.AddMessage("workspace path is {0}".format(arcpy.env.workspace))
arcpy.env.overwriteOutput = True
arcpy.env.qualifiedFieldNames = False
arcpy.AddMessage(arcpy.management.GetCount(sdeParcel))
arcpy.management.MakeFeatureLayer(sdeParcel, "parcel_lyr")
arcpy.AddMessage(arcpy.management.GetCount("parcel_lyr"))
arcpy.management.ChangeVersion("parcel_lyr","TRANSACTIONAL",version)
arcpy.AddMessage(arcpy.management.GetCount("parcel_lyr"))
arcpy.management.SelectLayerByLocation("parcel_lyr","WITHIN_A_DISTANCE",sdeParcel, -1, "NEW_SELECTION")
arcpy.AddMessage(arcpy.management.GetCount("parcel_lyr"))
edit = arcpy.da.Editor(arcpy.env.workspace)
arcpy.AddMessage("edit object created")
edit.startEditing(True, True)
arcpy.AddMessage("startEditing initiated")
edit.startOperation()
arcpy.AddMessage("startOperation initiated")
with arcpy.da.UpdateCursor("parcel_lyr",["PIN", "PARCELNB", "TOWNSHIP", "SECTION_", "BLOCK", "PARCEL"]) as letsUpdate:
arcpy.AddMessage("Update Object created")
for each in letsUpdate:
each[0] = each[2] + each[3] + each[4] + each[5]
arcpy.AddMessage("PIN is {0}".format(each[0]))
each[1] = "0"+each[0]
letsUpdate.updateRow(each)
edit.stopOperation()
arcpy.AddMessage("stopOperaton Initiated")
edit.stopEditing(True)
arcpy.AddMessage("stopEditing Initiated")
del aprx, sdeParcel, edit, letsUpdate
Any suggestions? Or obvious lack of my understanding?