Hi there
When programmatically publishing Map Image Services to ArcGIS Enterprise Portal, it is possible to define the service's title (the one which will be displayed in the item’s portal page after publishing) by modifying the .sddraft file. Please find an example below:
<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN>
layer_sharing_draft <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN>getWebLayerSharingDraft<SPAN class="punctuation token">(</SPAN>target_server_type<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"MAP_IMAGE"</SPAN><SPAN class="punctuation token">,</SPAN> service_name<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Create Service Definition Draft file</SPAN>
layer_sharing_draft<SPAN class="punctuation token">.</SPAN>exportToSDDraft<SPAN class="punctuation token">(</SPAN>sddraft_file_path<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Modify title in sddraft file </SPAN>
xml_sddraft <SPAN class="operator token">=</SPAN> DOM<SPAN class="punctuation token">.</SPAN>parse<SPAN class="punctuation token">(</SPAN>sddraft_file_path<SPAN class="punctuation token">)</SPAN>
title <SPAN class="operator token">=</SPAN> xml_sddraft<SPAN class="punctuation token">.</SPAN>getElementsByTagName<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Title'</SPAN><SPAN class="punctuation token">)</SPAN>
title<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>firstChild<SPAN class="punctuation token">.</SPAN>data <SPAN class="operator token">=</SPAN> service_title
<SPAN class="comment token"># save as new sddraft file</SPAN>
<SPAN class="keyword token">with</SPAN> codecs<SPAN class="punctuation token">.</SPAN>open<SPAN class="punctuation token">(</SPAN>new_sddraft_path<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"w"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"utf-8"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> f<SPAN class="punctuation token">:</SPAN>
xml_sddraft<SPAN class="punctuation token">.</SPAN>writexml<SPAN class="punctuation token">(</SPAN>writer<SPAN class="operator token">=</SPAN>f<SPAN class="punctuation token">,</SPAN> encoding<SPAN class="operator token">=</SPAN><SPAN class="string token">"utf-8"</SPAN><SPAN class="punctuation token">)</SPAN>
f<SPAN class="punctuation token">.</SPAN>close<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>new_sddraft_path<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># stage service </SPAN>
sd_file <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>StageService_server<SPAN class="punctuation token">(</SPAN>new_sddraft_path<SPAN class="punctuation token">,</SPAN> sd_file_path<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># upload service definition</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>UploadServiceDefinition_server<SPAN class="punctuation token">(</SPAN>sd_file<SPAN class="punctuation token">,</SPAN> target_url<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
While this works when creating services, it does not work when overwriting them. (when layer_sharing_draft.overwriteExistingService = True)
So when I overwrite an existing service, the title in the variable "service_title" is not shown as title in the service's portal page as I would expect.
The question is: Is it possible to edit the .sddraft file in such a way that the service title is changed when overwriting the service? Or is there another way to accomplish this?