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

How to execute schedule job in client script?

Pradeep J
Kilo Guru

Hi All,

I have written the onLoad Client script on the Table.

var rec = new GlideRecord('sysauto_script');

  rec.get('name', 'JSON Test4');

  if (typeof SncTriggerSynchronizer != 'undefined')

      SncTriggerSynchronizer.executeNow(rec);

  else

      Packages.com.snc.automation.TriggerSynchronizer.executeNow(rec);

But this is not executing the Scheduled Job. Please help me to solve this

Thanks

Pradeep D J

1 ACCEPTED SOLUTION

By making slight change in script include this will execute



i removed the last line from Script Include type:'AjaxUtils'



Thanks


Pradeep D J





PS: Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

2 REPLIES 2

Geoffrey2
ServiceNow Employee
ServiceNow Employee

You need to run SncTriggerSynchronizer.executeNow(rec) on the server. You can do this using GlideAjax.



Client Script:


function onLoad() {


  var ga = new GlideAjax('AjaxUtils');


  ga.addParam('sysparm_name', 'executeScheduledJob');


  ga.addParam('sysparm_job_name', 'JSON Test4');


  ga.getXML();


}



Script Include (assume the name is AjaxUtils😞


var AjaxUtils = Class.create();


AjaxUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  executeScheduledJob: function() {


  var rec = new GlideRecord('sysauto_script');


  if (rec.get('name', this.getParameter('sysparm_job_name'))) {


      if (typeof SncTriggerSynchronizer != 'undefined')


          SncTriggerSynchronizer.executeNow(rec);


      else


          Packages.com.snc.automation.TriggerSynchronizer.executeNow(rec);


      }


  },



  type: 'AjaxUtils'


});


By making slight change in script include this will execute



i removed the last line from Script Include type:'AjaxUtils'



Thanks


Pradeep D J





PS: Hit like, Helpful or Correct depending on the impact of the response