Hello,
I am curious to know how I might be able to return this output as a string. I am able to publish the tile package but, I am a bit confused on how to access this 'Derived Output'. I have tried "return publish_results" as well as "print(publish_results)" and got errors back. I will attach a link of the tool in question. https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/share-package.htm#GUID-D54F5...
Thank you in advance
try assigning the method to a variable and then accessing the output attributes like this:
result = arcpy.management.SharePackage(r"C:\states.lpkx", "", "",
"My Summary", "tag1, tag2", "My Credits",
"MYGROUPS", "My Group")
print(result.publish_results) # or print(result['publish_results'])
You could try
print(result)
#or
print(result['publish_results'])
or if you can look at the Results object in the debugger to see its structure.
print(result) returned a Boolean and print(result['publish_results']) returned the same error above
Seems that there is a disconnect in the documentation and the tool's derived output. Looking at the result in the debugger, there isn't any published result. "JSON response containing the service URL and portal item ID of the web layer."
if you use getOutput(2) on the result object, it returns the item id:
msg2 = result.getOutput(2)
...
'1s71a2emadethisidupea250c748er'
which can be used to create/ reference the item in portal:
https://domain.com/portal/home/item.html?id=msg2
Maybe that is what they meant? Wouldn't hurt to open a case with esri.
Hello, coming across this issue today, below are my findings.
I did a print(result.getOutput(0)), ... print(result.getOutput(2)) and it looks like this for me:
0: true
1: {"publishStatus":"completed","publishMessage":"","publishResult":{"type":"Map Service","serviceurl":"https://my.domain.org/server/rest/services/Hosted/mycachename/MapServer","serviceItemId":"123HostedTileLayerItemID4567890A","jobId":"123JobID4567890ABCDEFGHIJKLMNOPQR"}}
2: 123TilePackageItemID4567890ABCDE
I was after the Item IDs of the tile package and the published hosted layer, so this worked for me:
thisdict = json.loads(result.getOutput(1))
print("Tile Layer (hosted) Item ID on Portal: thisdict["publishResult"]["serviceItemId"])
print("Tile Package (tpkx) Item ID on Portal: result.getOutput(2))