Select to view content in your preferred language

Print Task: cannot read property of 'query' of undefined

6773
5
Jump to solution
02-16-2015 08:58 PM
davidrenz
Deactivated User

Hello,

I am trying to wire up some print functionality on an app that I am building.

I basically just copied the code from the JSAPI samples page ... just to get a sense of how it works,

When I click on the "Print" button, it heads off like the samples do, but I get the following error:

js.arcgis.com/3.12/esri/tasks/Geoprocessor.js?1424148233374:14 Uncaught TypeError: Cannot read property 'query' of undefined

I am not sure how to resolve this, it is the first time I have used the 10.2 print task.

I have also tried to publish my own templates as a print task and that is getting the same error.

Could someone point me in the right direction on this?

thx

David

Code is below:

        doPrint: function() {

            console.log("In the startup for print!");

            //esriConfig.defaults.io.alwaysUseProxy = false;

            //esriConfig.defaults.io.proxyUrl = "";

            // get print templates from the export web map task

            var printInfo = esriRequest({

                "url": this.printUrl,

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

            });

            printInfo.then(this.handlePrintInfo, this.handleError);

        },

        handlePrintInfo: function (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.preserveScale = true;

                plate.format = "PDF";

                plate.layoutOptions = {

                    "authorText": "Made by:  Esri's JS API Team",

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

                    "legendLayers": [],

                    "titleText": "Pool Permits",

                    "scalebarUnit": "Miles"

                };

                return plate;

            });

            // create the print dijit

            var printer = new Print({

                "map": global.MAP,  // ---> yes, I know <sigh!>

                "templates": templates,

                url: this.printUrl

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

            try {

                printer.startup();

            }

            catch (ex) {

                console.log(ex.message);

            }

            printer.on('print-start', function () {

                console.log('The print operation has started');

            });

            printer.on('print-complete', function (evt) {

                console.log('The url to the print image is : ' + evt.result.url);

            });

        },

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ChrisSergent
Deactivated User

Hopefully a working sample will help you. I'm not sure on yours, but I based my working code on Esri's print task sample too. I have a working sample that I built off of our own web services here: Print a Map

Click the Hammer

Click the Printer

And then you can print from there

The source code is here: JS Bin - Collaborative JavaScript Debugging

View solution in original post

0 Kudos
5 Replies
davidrenz
Deactivated User

I could really use a hand on this.

If someone could give me a hand, I would totally appreciate it.

When I run the print task and watch it in Fiddler, I get this::

# Result Protocol Host URL Body Caching Content-Type Process Comments Custom

2 304 HTTP www.currymap.org /arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task?f=json 0 private, must-revalidate, max-age=0 chrome:888

This is the error I am getting: --> it means nothing to me except that it keeps pointing back to the Geoprocessor.js file. Could this be a permissions or config issue?

Uncaught TypeError: Cannot read property 'query' of undefined

Geoprocessor.js?1424320198202:14

m.execute  init.js:717

y._createWrappers.n.forEach.b.(anonymous function)  PrintTask.js?1424320198202:9

s.execute   Print.js?1424320198202:7

f.printMap  Print.js?1424320198202:8

(anonymous function)   init.js:177

g.hitch_   MenuBase.js?1424320198202:8

k.onItemClick_   MenuBase.js?1424320198202:4

(anonymous function)   init.js:220

(anonymous function)

0 Kudos
ChrisSergent
Deactivated User

Hopefully a working sample will help you. I'm not sure on yours, but I based my working code on Esri's print task sample too. I have a working sample that I built off of our own web services here: Print a Map

Click the Hammer

Click the Printer

And then you can print from there

The source code is here: JS Bin - Collaborative JavaScript Debugging

0 Kudos
davidrenz
Deactivated User

hmmm .... your code worked with my map services and print service. cool!

Well, I guess I will use your stuff on this. I am not sure why the ESRI example code is not working with it, but whatever.

thx Chris!

davidrenz
Deactivated User

Chris,

I just wanted to follow up with you and once again thank you for your help.

Your example helped me see what I was NOT doing correctly.

So, thanks for taking the time to help me out .. it is very much appreciated.

thx.

David

ChrisSergent
Deactivated User

Always happy when I get to help someone on here. I receive a lot of help myself. Glad it helped.

0 Kudos