Select to view content in your preferred language

Printtask not working correctly

803
3
10-03-2020 05:20 AM
NovicaJosifovski
Occasional Contributor

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?

Tags (1)
0 Kudos
3 Replies
ManishPatel
Esri Contributor

Hi novica.josifovskigdi-net-esridist 

Does the network show the request being passed when you call the print if not then it potentially is unable to reach the printResult function.


What I can suggest you is you can try to modify you code as below:

printTask.execute(params, function(evt){
   //code snippet from your printResult function goes here....
});

Suspect the print execute is unable to reach to the function.

Cheers,

Manish

Cheers,
Manish
0 Kudos
ManishPatel
Esri Contributor

HiNovica Josifovski,

Just wondering if you managed to fix the code??

Cheers,

Manish

Cheers,
Manish
0 Kudos
Noah-Sager
Esri Regular Contributor

I would try catching a potential error with this format:

printTask.execute(params).then(printResult, printError);

And here it is in action:

https://codepen.io/noash/pen/gOPoxZj?editors=1000 

0 Kudos