I have a need for a custom map layout when printing from JSAPI web map. But I haven't been successful in publishing a custom template in ArcGIS Pro that works when called using the Javascript API (JSAPI).
Using the Print widget with the regular PrintingTools, as shown in this ESRI sample, works fine:
<SPAN class="keyword token">var</SPAN> print <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>
view<SPAN class="punctuation token">:</SPAN> view<SPAN class="punctuation token">,</SPAN>
<SPAN class="comment token">// specify your own print service</SPAN>
printServiceUrl<SPAN class="punctuation token">:</SPAN><SPAN class="string token">"https://myserver.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"</SPAN><SPAN class="punctuation token">,</SPAN>
container<SPAN class="punctuation token">:</SPAN> document<SPAN class="punctuation token">.</SPAN><SPAN class="token function">createElement</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"div"</SPAN><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></SPAN></SPAN>
The widget open the window on the left and gives me all the default layout printing options. I would like to create a custom layout.
Next, I've followed the instructions here and here, to create a *.pagx layout file in ArcGIS Pro (would be MXD in ArcMap) and share (publish) through Portal. The instructions read:
...To create and share the web tool with ArcGIS Enterprise, the folder containing your layout templates must be accessible to ArcGIS Server. If the folder is accessible to the server, you can register it with the server; otherwise, copy the folder's contents to the server from ArcGIS Pro when you share the web tool.
So in steps 5 and 9, ...
5. For the Layout Templates Folder parameter, click the browse button and browse to the folder where your layouts are stored.
...
9. Choose the same Layout Templates Folder that you specified when running the Export Web Maptool in step 5
...I've left the field blank, and then checked "Copy all data" (Step 12) to copy the template to the server during Sharing. There are no errors during the sharing process. I get this and then ...

...see the item in Portal. When I reference the REST URL for the new print service in JSAPI...
<SPAN class="keyword token">var</SPAN> print <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>
view<SPAN class="punctuation token">:</SPAN> view<SPAN class="punctuation token">,</SPAN>
<SPAN class="comment token">// specify your own print service</SPAN>
printServiceUrl<SPAN class="punctuation token">:</SPAN><SPAN class="string token">"https://myserver.com/arcgis/rest/services/Custom_GP_Services/New_Custom_print_test/GPServer/Export%20Web%20Map"</SPAN><SPAN class="punctuation token">,</SPAN>
container<SPAN class="punctuation token">:</SPAN> document<SPAN class="punctuation token">.</SPAN><SPAN class="token function">createElement</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"div"</SPAN><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></SPAN></SPAN>I get this jocular bit of messaging:

Anyone seen this before? There are no JS errors in the console. So I have little to go on.
Troubleshooting at the print service REST page, as shown here, creates PDF output but it's not based on my custom template.
Output:
