Alternate solution for current.sys_id in Scheduled job run script

jobin1
Tera Expert

Hi All,

 

The below code is working in BR but not in a scheduled job so what is the best way to replace gr.addQuery('sys_id', current.sys_id); in a scheduled job run script?

 

var gr = new GlideRecord('u_custom_integration');
 gr.addQuery('sys_id', current.sys_id);//not considering in scheduled job run script
 gr.setLimit(1);
 gr.query();
 if (gr.next()) {

//tried gr.addQuery('sys_id', getUniqueValue()); but not working

@Ankur Bawiskar Any idea?

 

15 REPLIES 15

RaghavSh
Kilo Patron

Current will not work in scheduled job as current is an object which is used on table.

 

Since BR runs on particular table, current is available. Schedule job does not have current object.

If you hardcode the sys id here, it will work;

 

var gr = new GlideRecord('u_custom_integration');
 gr.addQuery('sys_id', "  "); // pass sys id here
 gr.setLimit(1);
 gr.query();
 if (gr.next()) {

}

What is your exact req?
Please mark the answer correct/helpful accordingly.

 


Raghav
MVP 2023

jobin1
Tera Expert

No its should not hardcode. what's the solution here

You can store the sys id in system property and call the system property with below syntax:

var id =gs.getProperty('property name');

 

var gr = new GlideRecord('u_custom_integration');
 gr.addQuery('sys_id', id); 
 gr.setLimit(1);
 gr.query();
 if (gr.next()) {

}

 

If your id has to be dynamic then you need to specify that what is your requirement


Raghav
MVP 2023

How would you dynamically populate the sys_id? Requirement is to close all Major Incidents as long as the related, child incidents are already closed. As I'm checking the value of  'parent_incident' field, I would like to check it against the current incidentt