- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2015 04:02 PM
Hi folks
Anyone has idea about Scripts - Background result screen providing inaccurate information when a record update script under Scripts - Background. Just to exemplify the issue, when a record updates script is executed, it writes
"*** Script: Records to be updated:0
*** Script: Records to be updated:0
*** Script: Date Updated,Number,State,Caveat,Assignment Group,Date Created
*** Script: Date Updated,Number,State,Caveat,Assignment Group,Date Created"
The execution results however can be retrieved in Script Log Statements under System Log
30-10-2015 17:24:05 | Information | Records to be updated:1350 | *** Script |
30-10-2015 17:24:05 | Information | 30-10-2015 17:24:05,HR0055345,Check and File,HR Support,HR Managed Records Team,2015-05-13 00:11:34 | *** Script |
30-10-2015 17:24:05 | Information | 30-10-2015 17:24:05,HR0219116,Check and File,HR Support,HR Managed Records Team,2015-08-13 00:04:35 | *** Script |
30-10-2015 17:24:05 | Information | 30-10-2015 17:24:05,HR0070881,Check and File,HR Support,HR Managed Records Team,2015-05-21 00:49:35 | *** Script |
Please find the script below,
The target records were fortunately updated properly
var grHR = new GlideRecord('hr');
grHR.addEncodedQuery("active=true^state!=7^u_caveatISEMPTY^assignment_group=f7a3cdfa60b4f100d0b93a90c5b62e74");
grHR.query();
//Output the Total Number of Records retrieved by the query
gs.log('Records to be updated:' + grHR.getRowCount());
gs.print('Records to be updated:' + grHR.getRowCount());
// Print the column headers for the output list
gs.log('Date Updated,Number,State,Caveat,Assignment Group,Date Created');
gs.print('Date Updated,Number,State,Caveat,Assignment Group,Date Created');
while (grHR.next()) {
grHR.u_caveat = '8e34000b68d26100454fd59ef9c80f8b'; // HR Support
grHR.update();
var datToday = new GlideDateTime();
gs.log(datToday.getDisplayValue() + ',' + grHR.number + ',' + grHR.state.getDisplayValue() + ',' + grHR.u_caveat.getDisplayValue() + ',' + grHR.assignment_group.getDisplayValue() + ',' + grHR.sys_created_on);
gs.print(datToday.getDisplayValue() + ',' + grHR.number + ',' + grHR.state.getDisplayValue() + ',' + grHR.u_caveat.getDisplayValue() + ',' + grHR.assignment_group.getDisplayValue() + ',' + grHR.sys_created_on);
}
So here is the questions
1) why the discrepancy occurs between the run time output screen and the system logs with exactly the same script.
2) If memory serves me right, gs.log writes to system log whereas gs.print writes to console window (output window). It seems gs.log also tries to output to console as well?
Any advise would be given credits.
Kind regards,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2015 07:01 PM
Hi georgechen,
I hope you're doing great!
Were you able to give it a try by running your script again? Do you have any other further questions on this?
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2015 10:54 PM
Hi George,
Here goes some pointers that may be of help:
a) Yes. gs.log also prints in the screen when running the code from a background script
b) By looking at your code the line which displays the values of the updated record never ran when you ran the code from the background script; otherwise the last gs.print will at least have printed the commas. In other words, the information that you're showing in the log versus what's shown from the prints in the background script actually belong to different executions (runs) of the script at different times.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2015 10:57 PM
You could validate this reasoning by running your code again and the validating the log order by "Created On" date field in the Logs list.
Alternatively, you could try a different script, like the following:
var incident = new GlideRecord('incident');
incident.addEncodedQuery("active=true");
incident.query();
gs.log('Records to be updated:' + incident.getRowCount());
gs.print('Records to be updated:' + incident.getRowCount());
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2015 07:01 PM
Hi georgechen,
I hope you're doing great!
Were you able to give it a try by running your script again? Do you have any other further questions on this?
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2015 08:13 PM
Thanks Berny. Yes actually the script did update the target records correctly (as you suggested two threads were running one in back-end). I was able to verity the records with a search criteria (Active = True, Assignment Group = abc, Caveat is not empty , etc). I was just curious about why the output stated 0 records to be updated.
You have answered my question!