I'm having the same issue and I think its because the layer in in the "GPInMemoryWorkspace" and not on a disk.
When publishing to server, certain variables are substituted for g_ESRI_variable_x and declared at the top of the script. Not sure why server needs to do this - some of the variables in my scripts are just field names, like g_ESRI_variable_4 = u'F_AREA'. You can see the amended script in the arcgissystem folder on the server, e.g. \arcgisserver\directories\arcgissystem\arcgisinput\LFP\lfp01Setup.GPServer\extracted\v101\_python\LFP_01_Setup.py
I think the problem in your script may be to do with the current path. The help doc says that the Layer constructor needs
A string that includes the full path and file name of an existing layer (.lyr) file.
Your script doesn't contain a path, so maybe the working folder is different when running on the server. Try specifying the full path for "layer" in lines 3 and 4.
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.