- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2022 06:22 AM
Hi All,
I am writing a script in Run script activity in workflow to add 2 business days to current date and time and place it in a field. But my script is not returning proper value. It is throwing an error
Could you please guide
var scTask = new GlideRecord("sc_task");
scTask.addEncodedQuery("state=2"); //if state is work in progress
scTask.query();
if (scTask.next()) {
var startDate= gs.nowDateTime();
var days = 2;
//assuming there are 8 business hours
days = days*8;
var dur = new GlideDuration(60 * 60 * 1000 * days);
var schedule = new GlideSchedule('f4db82011b36a010cb721f42b24bcb27'); //put your schedule sys_id here
var end = schedule.add(startDate, dur);
scTask.field1=end;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2022 06:46 AM
hi @Renu
Try this:
var scTask = new GlideRecord("sc_task");
scTask.addQuery("request_item", current.sys_id); //added here
scTask.addEncodedQuery("state=2"); //if state is work in progress
scTask.query();
if (scTask.next()) {
var startDate= new GlideDateTime(); //changed here
var days = 2;
//assuming there are 8 business hours
days = days*8;
var dur = new GlideDuration(60 * 60 * 1000 * days);
var schedule = new GlideSchedule('f4db82011b36a010cb721f42b24bcb27'); //put your schedule sys_id here
var end = schedule.add(startDate, dur);
scTask.field1=end;
scTask.update(); //added here
}
Thanks,
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2022 12:51 AM
I think you just need to add an Update condition like scTask.update();
It will tell the script to update. 🙂