Select to view content in your preferred language

Need help with Printing - Export Web Map Task - Failed to create layer from service

5482
3
Jump to solution
10-21-2014 11:36 AM
DominicGervais
Emerging Contributor

I am trying to print a map that I made with arcgis server 10.2 and arcgis javascript api.

The problem is that I keep getting an error (code: 400, message: "Unable to complete operation.", details: Array[1], log: undefined, httpCode: 400).

which is more specifically -->

Unable to complete operation.

Error executing tool.: Layer "graphicsLayer8": Failed to create layer from service at http://MYSERVER/arcgis/rest/services/Tests/MyFirstMapService/MapServer/2. Layer "graphicsLayer9": Failed to create layer from service at http://MYSERVER/arcgis/rest/services/Tests/MyFirstMapService/MapServer/2. Layer "graphicsLayer10": Failed to create layer from service at http://MYSERVER/arcgis/rest/services/Tests/MyFirstMapService/MapServer/0. Failed to execute (Export Web Map). Failed to execute (Export Web Map Task).

I get the error if I try to do it via my web server or directly off the arcgis server by doing :

http://MYSERVER/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task/exec...

Here's the code for the printing part :

    printUrl = "http://MYSERVER/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";

var printInfo = esriRequest({

          "url": printUrl,

          "content": { "f": "json" }

        });

        printInfo.then(dojo.hitch(printUrl,dojo.hitch(myMap,handlePrintInfo)), handleError);

   function handlePrintInfo(resp) {

   var layoutTemplate, templateNames, mapOnlyIndex, templates;

          layoutTemplate = arrayUtils.filter(resp.parameters, function(param, idx) {

            return param.name === "Layout_Template";

          });

       

          if ( layoutTemplate.length === 0 ) {

            console.log("print service parameters name for templates must be \"Layout_Template\"");

            return;

          }

          templateNames = layoutTemplate[0].choiceList;

          // remove the MAP_ONLY template then add it to the end of the list of templates

          mapOnlyIndex = arrayUtils.indexOf(templateNames, "MAP_ONLY");

          if ( mapOnlyIndex > -1 ) {

            var mapOnly = templateNames.splice(mapOnlyIndex, mapOnlyIndex + 1)[0];

            templateNames.push(mapOnly);

          }

       

          // create a print template for each choice

          templates = arrayUtils.map(templateNames, function(ch) {

            var plate = new PrintTemplate();

            plate.layout = plate.label = ch;

            plate.format = "PDF";

            plate.layoutOptions = {

              "authorText": "Auteur.",

              "copyrightText": "<copyright info here>",

              "legendLayers": [],

              "titleText": "Un titre",

              "scalebarUnit": "Kilometers"

            };

            return plate;

          });

          // create the print dijit

          var printer = new Print({

            "map": myMap,

            "templates": templates,

            "url": printUrl

          }, dojo.byId("print_button"));

          printer.startup();

        }

        function handleError(err) {

          console.log("Something broke: ", err);

        }

Ce message a été modifié par : Dominic Gervais

0 Kudos
1 Solution

Accepted Solutions
DominicGervais
Emerging Contributor

I fixed the issue by changing the URL. Changed the "MYSERVER" part by the IP adress and It worked. It is probably due to the web adaptor.

View solution in original post

0 Kudos
3 Replies
DominicGervais
Emerging Contributor

Here's my code again since it seems it did'nt work the first time :

printUrl = "http://MYSERVER/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";

var printInfo = esriRequest({

          "url": printUrl,

          "content": { "f": "json" }

        });

        printInfo.then(dojo.hitch(printUrl,dojo.hitch(myMap,handlePrintInfo)), handleError);

  

   function handlePrintInfo(resp) {

  

   var layoutTemplate, templateNames, mapOnlyIndex, templates;

          layoutTemplate = arrayUtils.filter(resp.parameters, function(param, idx) {

            return param.name === "Layout_Template";

          });

         

          if ( layoutTemplate.length === 0 ) {

            console.log("print service parameters name for templates must be \"Layout_Template\"");

            return;

          }

          templateNames = layoutTemplate[0].choiceList;

          // remove the MAP_ONLY template then add it to the end of the list of templates

          mapOnlyIndex = arrayUtils.indexOf(templateNames, "MAP_ONLY");

          if ( mapOnlyIndex > -1 ) {

            var mapOnly = templateNames.splice(mapOnlyIndex, mapOnlyIndex + 1)[0];

            templateNames.push(mapOnly);

          }

         

          // create a print template for each choice

          templates = arrayUtils.map(templateNames, function(ch) {

            var plate = new PrintTemplate();

            plate.layout = plate.label = ch;

            plate.format = "PDF";

            plate.layoutOptions = {

              "authorText": "Auteur.",

              "copyrightText": "<copyright info here>",

              "legendLayers": [],

              "titleText": "Un titre",

              "scalebarUnit": "Kilometers"

            };

            return plate;

          });

          // create the print dijit

          var printer = new Print({

            "map": myMap,

            "templates": templates,

            "url": printUrl

          }, dojo.byId("print_button"));

          printer.startup();

        }

        function handleError(err) {

          console.log("Something broke: ", err);

        }

0 Kudos
TracyArchibald
Regular Contributor

Hey Dominic!

I was having the same issue.  It's a known bug in 10.1-10.2.2.  10.3 is supposed to have a fix.  I'm in the midst of testing it and it seems better.  I've come across a different issue though, so I'm not entirely certain it's fully functional yet...

0 Kudos
DominicGervais
Emerging Contributor

I fixed the issue by changing the URL. Changed the "MYSERVER" part by the IP adress and It worked. It is probably due to the web adaptor.

0 Kudos