- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 06:49 AM
I'm attempting to run a background script to update some duration values on the sc_req_item table (calendar_duration and business_duration fields). Below is the query that I am trying to run. However, when I run it using background scripts, it updates a record, sometimes two or three and then craps out. However if I comment out line 17 and use a gs.log to print out the values that I calculate on lines 11 and 15, I get rows and rows of data.
When searching the community, I found this item (Background Script not updating all returned Glide Records ), which is an issue that is similar to mine. Is this a legit bug? If so, what's the alternative way to run this script in order to update the duration values?
var grRI = new GlideRecord('sc_req_item');
grRI.addEncodedQuery('state=3^ORstate=5^ORstate=7'); // states 3,5,7 (closed complete, closed rejected, closed cancelled);
//grRI.addQuery('business_duration','NULL');
//grRI.addQuery('calendar_duration','NULL');
grRI.query();
while (grRI.next()) {
// Set calendar duration
grRI.calendar_duration = gs.dateDiff(grRI.sys_created_on.getDisplayValue(),grRI.closed,false);
// Set business duration
var dur = calcDurationSchedule(grRI.sys_created_on, grRI.sys_updated_on);
grRI.business_duration = dur;
grRI.update();
}
function calcDurationSchedule(start, end) {
// Get the user
var usr = new GlideRecord('sys_user');
usr.get(gs.getUserID());
// Create schedule - BCBSLA 8-5 Weekdays schedule and pass in the users timezone
var sched = new GlideSchedule('97fb0a3e87252100e08f276709434dfc',usr.time_zone);
// Get duration based on schedule/timezone
return (sched.duration(start.getGlideObject(), end.getGlideObject()));
}
Thanks for any help you can offer.
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 10:43 AM
Thanks to everyone for your help. I was able to get the columns to update finally. For some odd reason, the only way to get the script to work properly was to use a Fix Script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 06:50 AM
Hi Patrick
Try running it as an on demand scheduled job
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 07:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 07:22 AM
Correct. Create one for running a script and making it for on demand execution. You copy your code over there and then hit execute.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 06:51 AM
You may want to include some gs.log in the middle if you want to see the progress that is doing and a gs.log at the end so that you can check through the logs when it ends.
Thanks,
Berny