second .update() in my Scheduled JOB script not working
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Saturday - last edited Sunday
Hello! Hoping someone out there can tell me why the second of two .update() statements (using the same gliderecord object) isn't working. The first .update() works fine.
I'm running this on a PDI of Zurich. My first goal is to have a Scheduled JOB manipulate a Scheduled Report and then trigger that Scheduled Report. My second goal however is to restore the fields I had modified back to their original values before committing a subsequent .update(). This will allow the job to run multiple times and always start with the original field values in the report. This is the part that isn't working for me.
Give it a shot and let me know the reason and your proposed correction(s). Thank you!
// below is the script in my Scheduled JOB (not in the Scheduled Report it modifies)
// this is extremely useful when recipients should be whoever appeared in the Scheduled Report
modifyScheduledReportParmsThenRunIt();
function modifyScheduledReportParmsThenRunIt() {
var grScheduledReport = new GlideRecord('sysauto_report');
if (!grScheduledReport.get('name', 'test Scheduled REPORT')) { // this report exists
gs.info('cannot find report in sysauto_report table');
return false;
}
// save off original values for the very end
var orig_user_list = grScheduledReport.user_list; // GlideList
var orig_address_list = grScheduledReport.address_list; // comma-separated list of email addresses
// begin modifying parms of the scheduled report before triggering its execution
// let's add foo@bar.com as a recipient of the eventual email
if (grScheduledReport.address_list.getDisplayValue().length > 0) {
grScheduledReport.address_list += ', '; // prep with leading comma if necessary
}
grScheduledReport.address_list += 'foo@bar.com';
// let's add the ServiceNow User 'SlimJim' as a recipient of the eventual email
var grUser = new GlideRecord('sys_user');
if (!grUser.get('user_name', 'SlimJim')) {
gs.info('cannot find "SlimJim" in sys_user table');
} else {
if (grScheduledReport.user_list.indexOf(grUser.sys_id) < 0) {
if (grScheduledReport.user_list != '') {
grScheduledReport.user_list += ', ';
}
grScheduledReport.user_list += grUser.sys_id;
}
}
var res1 = grScheduledReport.update(); // required update prior to triggering report
gs.info('first update returned ' + res1); // this seems to work fine
SncTriggerSynchronizer.executeNow(grScheduledReport); // run the modified Scheduled Report
//////////////////////////////////////////////////////////////////////////////////
////////////// THE BELOW PART DOESN'T WORK AND I DON'T KNOW WHY!!! //////////////
//////////////////////////////////////////////////////////////////////////////////
// restore original values to the Scheduled Report
grScheduledReport.address_list = orig_address_list;
grScheduledReport.user_list = orig_user_list;
var res2 = grScheduledReport.update(); // call update after trigger to put everything back to original
gs.info('second update returned ' + res2);
// even though SN returns the sys_id, the update back to original values didn't persist -- I can still see foo@bar.com as an Email Recipient and SlimJim as a User recipient when I open the Scheduled Report to view/edit it
return true; // last line must return a true or false
}
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Saturday
we don't know your script or requirement so can't help
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sunday
