Trying to consume a Geoprocessing Service (webtool) out of ArcGIS Pro with JSAPI 3.31 in WAB DE.
I have geoprocessing service that's supposed to prepare a web map for printing. This was adapted from the example given in the documentation here - ConvertWebMapToArcGISProject—ArcPy | Documentation. Service is consumed from JSAPI (WAB widget) and would like users to be able to save/open the resulting PDF from the app.
The service readily produces PDF output in a server directory but every attempt to return some reference to it (as file or filepath) so that I can interact with it in Javascript has failed so far. Numerous other Geonet threads have suggested various fixes, and I've tested them all.
The error I get consistently points to the setting of parameter:
RuntimeError: Object: Error in setting parameter as text
Failed to execute<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
I've tried both
arcpy.SetParameter()
and
arcpy.SetParameterAsText(). <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
In my geoprocessing tool, I've tried type "String" with "SetParameterAsText" and passing the path to the file, and I've tried type "File" with "SetParameter" and passing a reference to the actual file.
I've tried creating the file in
arcpy.env.scratchWorkspace<SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
as suggested in one thread, then doing the following to get a proper i/o file reference to it (as suggested elsewhere):
uniqueID <SPAN class="operator token">=</SPAN> str<SPAN class="punctuation token">(</SPAN>uuid<SPAN class="punctuation token">.</SPAN>uuid1<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
WebMapPDF <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>scratchWorkspace<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'WebMap_{0}.pdf'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>uniqueID<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
layout<SPAN class="punctuation token">.</SPAN>exportToPDF<SPAN class="punctuation token">(</SPAN>WebMapPDF<SPAN class="punctuation token">)</SPAN>
PDFOutputFile <SPAN class="operator token">=</SPAN> open<SPAN class="punctuation token">(</SPAN>WebMapPDF_forDownload<SPAN class="punctuation token">)</SPAN>
PDFOutputFile<SPAN class="punctuation token">.</SPAN>close<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SetParameter<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> PDFOutputFile<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># I only have one GetParameter, so this is index 1</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>
In JS, I was hoping to do something like this with a reference to the file:
gp<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getResultData</SPAN><SPAN class="punctuation token">(</SPAN>jobInfo<SPAN class="punctuation token">.</SPAN>jobId<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"PDFOutputFile"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>printComplete<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
printComplete <SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>result<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
window<SPAN class="punctuation token">.</SPAN><SPAN class="token function">open</SPAN><SPAN class="punctuation token">(</SPAN>result<SPAN class="punctuation token">.</SPAN>url<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</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>but haven't even gotten as far as getting an error because the geoproc service call keeps failing. As stated above, replacing the scratchspace reference with an actual server path and removing the setparameter, creates a beautiful PDF. So thee issue has to be with my last line of Python that set the output parameter or with configuring that parameter in the tool. Or potentially in how these get passed into the widget? Here is how I set up my Geoprocessor parameters....
<SPAN class="keyword token">var</SPAN> gpParams <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">"Web_Map_as_JSON"</SPAN> <SPAN class="punctuation token">:</SPAN> webMapAsJSON<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// do I need to include my PDFOutfile in the params ?</SPAN>
<SPAN class="comment token">// var gpParams = {"Web_Map_as_JSON" : webMapAsJSONasString, </SPAN>
<SPAN class="comment token">// "PDFOutputfile" : call it what?? };</SPAN>
gp<SPAN class="punctuation token">.</SPAN><SPAN class="token function">submitJob</SPAN><SPAN class="punctuation token">(</SPAN>gpParams<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>completeCallback<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>statusCallback<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>