Hello,
When I publish the KmlToLayer as below, I can publish the Group Layer as a map service. Gp Server publishes group layer parameter type as GpString and can display it as Map Service.




But when I try to do the same output with Arcpy as follows, the lyr file is only recognized as a file and the result map service is empty.
result_gl <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListLayers<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"GroupLayer"</SPAN><SPAN class="punctuation token">,</SPAN> df<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># ...</SPAN>
result_group_layer_path <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>scratchWorkspace <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\\"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"scratch.lyr"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SaveToLayerFile_management<SPAN class="punctuation token">(</SPAN>result_gl <SPAN class="punctuation token">,</SPAN> result_group_layer_path<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># ...</SPAN>
<SPAN class="comment token"># Only this one adds result layer to display others not.</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> result_group_layer_path<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Or</SPAN>
<SPAN class="comment token"># arcpy.SetParameter(1, result_gl)</SPAN>
<SPAN class="comment token"># Or</SPAN>
<SPAN class="comment token"># arcpy.SetParameter(1, arcpy.mapping.Layer(result_group_layer_path))</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>

When I publish this with "View results with a map service option" , the output parameter is as follows not as a map service.
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"paramName"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"RESULT"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"dataType"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"GPDataFile"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"value"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"url"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2F....gpserver%2Fj069a1ca799304125882f8e172a4626b5%2Fscratch%2Fscratch.lyr" target="_blank">https://....gpserver/j069a1ca799304125882f8e172a4626b5/scratch/scratch.lyr</A><SPAN>"</SPAN></SPAN>
<SPAN class="punctuation token">}</SPAN>
<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>What is the difference between the KmlToLayer model above and the my ArcPy model outputs?
What should I do in order for the ArcGIS server to display the result lyr file (group layer) as a map service?