Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Trigger notification via catalog item

Sharath807
Tera Contributor

Hi all , I have a requirement to trigger  scheduled job (in which event is called through which respective notification will be triggered)  that am selecting in list collector variable in catalog item ( currently there are 3 scheduled job).. So i created a BR in Sc_req_item table to trigger Scheduled job . But the BR script is not working as expected. Any help is appreciated.. Thanks in advance. 

BR script:

(function executeRule(current, previous /*null when async*/) {

gs.info('Business Rule execution started for RITM: ' + current.number);


gs.info('Available variables in current: ' + JSON.stringify(current.variables));


var jobList = current.variables.template;
var bodyContent = current.variables.email_content;


gs.info('Retrieved job list: ' + jobList);

if (jobList) {
gs.info('Job list is defined and non-empty.');

var jobArray = jobList.split(','); 
gs.info('Parsed job array: ' + JSON.stringify(jobArray));

for (var i = 0; i < jobArray.length; i++) {
var jobSysId = jobArray[i].trim(); 
gs.info('Processing job Sys ID: ' + jobSysId);

var job = new GlideRecord('sys_trigger');
if (job.get(jobSysId)) {
gs.info('Triggering scheduled job: ' + jobSysId);

try {

var jobScript = job.script; 
if (jobScript) {
eval(jobScript); 
gs.info('Executed script for job: ' + jobSysId);
} else {
gs.warn('No script found for job: ' + jobSysId);
}
} catch (e) {
gs.error('Error executing job script for job ' + jobSysId + ': ' + e.message);
}
} else {
gs.warn('Job not found: ' + jobSysId);
}
}
} else {
gs.warn('No jobs selected in the list collector or variable is undefined.');
}
})(current, previous);

 

Screenshot (59).png

5 REPLIES 5

Sharath807
Tera Contributor

@RikV  hi any update you have on this?