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

Hi Mahendra,

The custom field I am having is on RITM table only

As suggested I have added a wait for condition activity after the catalog task . The wait for condition contains if approval status (custom field) is approved, but even after the field value changes to approved, it is still in the same wait for condition activity, it is not moving out from that

Please guide what I am missing here

 

@Ankur Bawiskar  Kindly suggest 

 

hello,

instead of using this in wait for condition activity copy the same script and paste it in the timer activity and try that should work.

Before that remove the wait the condition activity and replace it with timer activity and then paste the script and try .

Hope this helps 

Mark the answer correct if this helps you

Hi,

In timer activity, there is only we can set duration but not any conditions.

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