How to set due date on sc_task using workflow but after the generation of catalog task

Srinivas K
Tera Contributor

Hi All,

I am having a requirement where I need to set the due date of the catalog task when a field value changes in RITM.

Until that time due date should be empty

1. Create a request in service portal

2. Req, RITM, Sc_task are generated via a workflow associated with the catalog item

3.Once sc_task is generated I need to check a field value on RITM. If the field value is 'Approved' then only I should start the counter of sc_Task, until that time it should not start

Please guide me how to achieve this.

1 ACCEPTED SOLUTION

Hello Srinivas K,

Please check with below script:

var scTask = new GlideRecord("sc_task");
scTask.addEncodedQuery("state=2"); //if state is work in progress
scTask.query();
if (scTask.next()) {
var startDate = new GlideDateTime();
var days = 2;
var hours = 9; // put the hours like 9 hours means 1 days. If you want you can put 24 hours for 1 day
var duration = new GlideDuration(60 * 60 * 1000 * hours * days); 
var schedule = new GlideSchedule('your schedule sys_id'); //put your schedule sys_id here
var end = schedule.add(startDate, duration);
scTask.end_date=end;
scTask.update();
}

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

View solution in original post

8 REPLIES 8

Uncle Rob
Kilo Patron

Ok, are you really saying that when the RITM is approved (even though the sc_task is already created) then you want to update the sc_task with a date?

Hi Robert, Yes , so we should update due date on sc task not immediately when the task is generated, but after some specific condition at some later point.The requirement is for integrations

1. Creates a request at service portal 2. REQ, RITM , SCTask are generated 

3.On the SCTask , we are checking whether it is integrated ritm or not, here the due date should be empty

4.if integrated and approved at other side(we can confirm it via custom field is approved), then only we need to set due date to 2  business days 

Please guide how this can be achieved 

 

 

 

 

 

 

Mahendra RC
Mega Sage

Hello Srinivas,

If the field that is used to identify if the RITM is integrated or not is on the RITM table then you can use wait for activity and can wait until the RITM's custom field is updated as approved. So once the RITM is approved the Wait for condition will be completed. After this you can use Run script and use the below script:

var scTask = new GlideRecord("sc_task");
scTask.addEncodedQuery("put your query here");
scTask.query();
if (scTask.next()) {
var gdt = new GlideDateTime();
var weekDay = gdt.getDayOfWeek();
if (weekDay == 4 || weekDay == 5) {
gdt.addDays(4); 
} else if (weekDay == 6) {
gdt.addDays(3);
} else {
gdt.addDays(2);
}
scTask.due_date.setDateNumericValue(gdt.getNumericValue());
scTask.update();
}

If your custom field is on sc_task table then you have to somehow check if the sc_task is integrated and approved ("wait for condition" will trigger when there will be any update on sc_req_item table. The workflow evaluates the Wait for condition activity each time the current record is updated). In this case may be you can the BR to update the due_date on sc_task based on the custom field update if there is no other dependency that needs to be handled in workflow. You can use the similar code in your BR as well.

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

 

Hi Mahendra, Is adding the run script only way to achieve this in workflow can't we add any block and directly calculate due date like how we do it in catalog task activity..? I am also having a schedule excluding weekends and holidays with a 8am -5pm schedule .How can I calculate along with it.please guide