The CreatorCon Call for Content is officially open! Get started here.

Hi , I was wondering if there is a way to force a UI action process to run in the backgrounf?

mok
Kilo Contributor

Hi ,

I am trying to force a process to run in the background after clicking a UI action/button on a form, currently the process locks out the screen and this takes time before moving onto the next item

is there a way to do this!?

1 ACCEPTED SOLUTION

Yup it would definitely stop the screen from locking out. Instead you would have a very lightweight AJAX call running in the background checking status while the actual work is done on a worker node, so it will also not take up any user semaphores.



Please do let me know if you get this working!



-Jon


Sent from my iPhone


View solution in original post

13 REPLIES 13

Jon Barnes
Kilo Sage

Client-side UI Action is a good plan and you could use a GlideScriptedHierarchicalWorker to keep track of it.   look at a OOTB script include called ChangeConflictAJAXProcessor for a good example.   you could do a GlideAjax call from the UI Action client script to the script include you create which kicks off the GlideScriptedHierarchicalWorker process.



I had to do this same thing before as well, but at the time I didn't know about the Hierarchical worker, so I wrote a custom solution, but it should be the same concept.   The other thing you may want to think about is locking the record (using ACLs) during the time the background process is running if it runs for a long time and may update the record at the end, you may not want anybody else updating it in the mean time.



I did this with ACLs and put a message at the top of the form for any other users visiting that record so they knew why the record was locked.


mok
Kilo Contributor

Hi Jonathan ,



Much appreciated , I am quite new to Service NOW , I have a few more questions related to this, So I have created the UI Action which calls the Script Include , I guess based on your solution above "you could do a GlideAjax call from the UI Action client script to the script include you create which kicks off the GlideScriptedHierarchicalWorker process."










I have something like this so far:



var track= new GlideScriptedHierarchicalWorker();  


track.setProgressName('Track Progrress');  


track.setBackground(true);  


track.setScriptIncludeName('Is this the same script include name I am within that i need to call?');  


track.setScriptIncludeMethod('this would be dependant on the script include ');  


track.putMethodArg('something', something);  


track.start();




// Am I triggering the "GlideScriptedHierarchicalWorker process" within the same script include as per your solution above if so how exactly or do i have to put   put the above code in another place



Thankyou once again and apologies if my questions are redundant !!


you can use the same script include (or a different one), but definitely would be a different function. This is where you would call a script include to do the actual work of the UI action.   the main usefulness of the hierarchical worker is that you can check status of the worker, and report back to the UI when completed.



there is an example of that status checking function in the example script include as well.



and the corresponding client side part for this example function is in a UI Macro called "change_request_conflict_progress".   you can see how they put it on a timer and check the status of the worker every so often to keep the user up to date.   it is a very nice user experience for long running transactions.



hope that helps


mok
Kilo Contributor

Thanks ... that definately helps.. I am assuming this would stop the user screen/form   from locking out during the process.


Yup it would definitely stop the screen from locking out. Instead you would have a very lightweight AJAX call running in the background checking status while the actual work is done on a worker node, so it will also not take up any user semaphores.



Please do let me know if you get this working!



-Jon


Sent from my iPhone