JavaScript API Print and Print Template "execute not define"

661
6
Jump to solution
08-04-2021 07:56 AM
LeeRipma
New Contributor II

Hi Esri Community,

We run into a problem, We generate the Custom Maps and try to implement the "Print" API with "Print Templates" that listed in documentation here: 

https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-print.html

When we implement the JavaScript Request but it's give  Error "(index):23 Uncaught ReferenceError: execute is not defined"

I checked the Documentation and there is noting to add anything in the Require for Execute.

 

Here is the Code Example that we are using:

  <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://js.arcgis.com/4.20/"></script>

require([
"esri/config",
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/layers/MapImageLayer",
"esri/identity/OAuthInfo",
"esri/identity/IdentityManager",
"esri/Basemap",
"esri/layers/VectorTileLayer",
"esri/layers/TileLayer",
"esri/rest/print",
"esri/rest/support/PrintTemplate",
"esri/rest/support/PrintParameters",
"esri/tasks/QueryTask",
"esri/rest/query"
], function(esriConfig, Map, MapView, FeatureLayer, MapImageLayer, OAuthInfo, esriId, Basemap, VectorTileLayer, TileLayer, Print, PrintTemplate, PrintParameters, QueryTask, Query) {


We create our Maps like this:

// Income Map
    var map = new Map({ basemap: "arcgis-topographic" });
    var view = new MapView({ map: map, center: [-94.7148669, 38.9065419], zoom: 14, container: "viewDiv2" });
    const income_main = new MapImageLayer({ portalItem: { id: "ID" } });
    map.add(income_main);

	esriConfig.request.interceptors.push({ urls: Zipcode_Layer, before: function (params) {
	params.requestOptions.query = params.requestOptions.query || {};
	params.requestOptions.query.token = access_token; },});

   
    var zipcode = new FeatureLayer({
		url: Zipcode_Layer
    });
    map.add(zipcode);

 

After Map Creation we implement this code for Print API:

 

 var url55 = "https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task/execute";
	 const template = new PrintTemplate({
     format: "png",
     exportOptions: {
       dpi: 300
     },
     layout: "a4-portrait",
     layoutOptions: {
       titleText: "Gillette Stadium",
       authorText: "Thomas"
     }
    });
    const params = new PrintParameters({
     view: view,
     template: template
    });
   // execute(url50, params).then(printResult).catch(printError);
    execute(url55, params).then(printResult).catch(printError);

 

But it's give an error "(index):23 Uncaught ReferenceError: execute is not defined" Is there anyone who can help to fix the problem...

Thank You 

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor II
0 Kudos
6 Replies
ReneRubalcava
Frequent Contributor II

It would look like this.

 

 

require([
  "esri/rest/print"
], function(print) {
  print.execute(url, params);
});

 

 

The execute method exists on the print module you imported.

The code snippet in the doc assumes you are using ES6 import syntax.

import { execute } from "@arcgis/core/rest/print";

execute(url, params);
LeeRipma
New Contributor II

Hi Rena Rubalcava, Thanks for your answer when I implement the code that you provide it's bypass that problem but still giving error

"Error executing tool. Export Web Map Task : Required 'mapOptions.extent' property missing from web map JSON. Failed to execute (Export Web Map). Failed to execute (Export Web Map Task)."

0 Kudos
ReneRubalcava
Frequent Contributor II

Ok, I checked this out. "png" is not a format option. It's png8 or png32. Change that and it should work.

https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-PrintTemplate.html#f...

0 Kudos
LeeRipma
New Contributor II

I even added the Extent in the Map as well.

 

 var map = new Map({ basemap: "arcgis-topographic" });
    var view = new MapView({ map: map, extent: { xmin: -9177811, ymin: 4247000, xmax: -9176791, ymax: 4247784, spatialReference: 102100 },  zoom: 14, container: "viewDiv2" });
    const income_main = new MapImageLayer({ portalItem: { id: "ID" } });
    map.add(income_main);

	esriConfig.request.interceptors.push({ urls: Zipcode_Layer, before: function (params) {
	params.requestOptions.query = params.requestOptions.query || {};
	params.requestOptions.query.token = access_token; },});

   
    var zipcode = new FeatureLayer({
		url: Zipcode_Layer
    });
    map.add(zipcode);
	 var url50 = "https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";
	 const template = new PrintTemplate({
     format: "PNG32",
     exportOptions: {
       dpi: 300
     },
     layout: "a4-portrait",
     layoutOptions: {
       titleText: "Gillette Stadium",
       authorText: "Thomas"
     }
    });
    const params = new PrintParameters({
     view: view,
     template: template
    });
	  
   
   // execute(url50, params).then(printResult).catch(printError);
  
    var imageExport = print.execute(url50, params);

	  console.log(imageExport);
  

 

0 Kudos
LeeRipma
New Contributor II

@ReneRubalcava  Did you check this, Where I already update the PNG and Add the Extent but still giving me error for Extent

0 Kudos
ReneRubalcava
Frequent Contributor II
0 Kudos