Alternate solution for current.sys_id in Scheduled job run script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 12:56 AM - edited 12-07-2022 02:35 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 01:16 AM - edited 12-07-2022 01:22 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 02:07 AM
No its should not hardcode. what's the solution here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 02:18 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2023 08:35 AM
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