Get instance of GlideScriptedHierarchicalWorker via progressID

ducdhm
Giga Contributor

Hi guys,

Do you know how to get instance/record of GlideScriptedHierarchicalWorker by using progressID?

Example: I have a code for Worker like:

var worker = new GlideScriptedHierarchicalWorker();

worker.setProgressName('Import Services');

worker.setBackground(true);

worker.setScriptIncludeName('x_ausgh_snsc.SaraConsumerWorker');

worker.setScriptIncludeMethod('run');

worker.putMethodArg('targetCatId', targetCatId);

worker.start();

var progressID = worker.getProgressID();

I want to get worker in other code via progressID. So how can?

5 REPLIES 5

xMTinkerer
Giga Expert

Hello! Man, I would love to get more information about this too. Did you get any more details? Mostly I'd like to be able to monitor the processes and see how many are still running.


sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Duc,



What about going with a GlideRecord directly to "sys_progress_worker" using the name of the job, after job has been started?



Like:



var gr = new GlideRecord("sys_progress_worker");


gr.addQuery('name', '=', 'Data Archiving');


gr.query();



while(gr.next()){


gs.print('The progress worker job state is: ' + gr.state.toString() + ' and the Completion code is: ' + gr.state_code.toString());


}



The above code gives in my case:



[0:00:00.003] Script completed in scope global: script



*** Script: The progress worker job state is: complete and the Completion code is: success


Regards,


Sergiu


john_roberts
Mega Guru

What are you looking to do with the worker once you retrieve it again? I think the prefered option would be to use GlideExecutionTracker but the API is far too limited for scoped apps to do anything useful.


For example, getBySysID is the method you would need and it only works in global.


cc. Bobby Edmonds


SwastikC
Tera Contributor

How do I cancel a worker if it has started? Need to implement a cancel functionality.