How to cancel PrintTask in JS API 4

588
5
01-04-2021 10:20 AM
by Anonymous User
Not applicable

Is it possible to cancel a PrintTask. I don't see any cancelJob() method in the API documentaion. I see a cancelJob() in the Geoprocessor methods. I was wondering if there is something like that for the PrintTask. Would be helpful. Users sometimes submit large maps on accident and have to wait a few minuets for the task to end. 

Does anyone have any ideas ? 

Thanks, 

 

Tags (3)
5 Replies
JohnGrayson
Esri Regular Contributor

Check out the 'requestOptions' (RequestOptions) parameter of the execute(...) method; maybe the 'signal' (AbortSignal) property is something to try out.  This might allow you to build the UI so you can allow the user to continue using the UI without having to wait for a response.

JohnGrayson
Esri Regular Contributor

...and here's a quick codepen showing this concept: https://codepen.io/john-grayson/pen/LYRmGxY 

by Anonymous User
Not applicable

Wow I appreciate the codepen! I see what you're doing. 

Nice, It works on Synchronous but I have this on Asynchronous. I tried to switch it to Synchronous but it times out after 60 seconds. Even though I change the time limit from 60seconds to 120 seconds. Weird. 

Is there a way I can do this with Asynchronous. It's weird. It does work on Asynchronous but it still goes through and keeps fetching until the last one and then it cancels it. 

0 Kudos
JohnGrayson
Esri Regular Contributor

Do you have a codepen/jsbin showing the issue?  Maybe make a copy of mine and modify it so we can experience the issue described?  The concept for the shared code is to provide a UX that allows the user to cancel and continue using the app regardless of if/when the print calls themselves get canceled, but this might not be what you're after.

0 Kudos
by Anonymous User
Not applicable

I will try to whip something up. 

It's just that you have to change the setting to Asynchronous on the server side. In the manager setting for the service. So I will have to try and figure that out. Thanks for all the help so far! 

0 Kudos