AnsweredAssumed Answered

Printtask not working correctly

Question asked by novica.josifovskigdi-net-esridist Employee on Oct 3, 2020
Latest reply on Oct 12, 2020 by manishpatelesriaustralia-com-au-esridist

I am trying to use printTask as shown below, but it's not going in the printResult function. 

function printImage() {

                        var printTask;
                        var params = new PrintParameters();

                        if (sentScale == 1000) {
                          
                            printTask = new PrintTask('http://10.10.100.50:6080/arcgis/rest/services/karpos/Print_Karpos/GPServer/Export%20Web%20Map');
                            params.map = map;
                        }
                        else if (sentScale == 2500) {
                           
                            printTask = new PrintTask('http://10.10.100.50:6080/arcgis/rest/services/karpos/Print_Karpos/GPServer/Export%20Web%20Map');

                            params.map = map;
                        }

                        var template = new PrintTemplate();
                        template.format = 'JPG';
                        template.layout = 'MAP_ONLY';
                        template.preserveScale = false;
                        params.template = template;
                        console.log("params", params)

                        //printTask.execute(params).then(printResult);
                        printTask.execute(params, printResult);
                    }
                    // PRINT IMAGE



                    // PRINT RESULT
                    function printResult(evt) {
                        imageUrl = evt.url;
                        setCookie('imageUrl', imageUrl, 1);

                        if (reportType == 1) {

                            printReport();
                        }
                        if (reportType == 2) {
                            console.log("reporttype2 start")
                            var printTaskLegend;
                            var printPars = new PrintParameters();
                            printPars.map = map;

                            if (sentScale == 1000) {
                                console.log("reporttype2 1000")

                                printTaskLegend = new PrintTask('http://10.10.100.50:6080/arcgis/rest/services/karpos/Print_Karpos/GPServer/Export%20Web%20Map');
                                printPars.map = map;
                            }
                            else if (sentScale == 2500) {
                                console.log("reporttype2 2500")

                                printTaskLegend = new PrintTask('http://10.10.100.50:6080/arcgis/rest/services/karpos/Print_Karpos/GPServer/Export%20Web%20Map');
                                printPars.map = map;
                            }

                            var template = new PrintTemplate();
                            template.format = 'JPG';
                            template.layout = 'Print_legend_included';
                            template.preserveScale = true;
                            printPars.template = template;
                            printTaskLegend.execute(printPars, printImageLegend);
                            //printTaskLegend.execute(printPars).then(printImageLegend);
                            console.log("reporttype2 end")

                        }
                    }

I am printing out the params with console.log in printImage and according to this, I think it ok?

I tried to use both printTask.execute(params).then(printResult); as well as printTask.execute(params, printResult);

but it just does not go into printResult. Anyone has any idea why?

Outcomes