How to auto-set Due Date +5 Days (Calendar Days vs Business Days) on SC Task Creation?

tilekarnilesh
Giga Guru

Hi all,

I have a requirement where, when an SC Task is created in ServiceNow, I want the Due Date field to automatically populate 5 days after the creation date.

I want to know how to achieve this in two ways:

  1. Calendar Days: Simply add 5 days including weekends.
  2. Business Days Only: Add 5 working days (skip Saturdays and Sundays).

Questions:

How can I handle both scenarios in a script?


Thanks in advance for your help!

5 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@tilekarnilesh 

you can use this script for 1st scenario to add 5 days

var nowTime = new GlideDateTime();
nowTime.addDaysUTC(5);
current.due_date = nowTime;

you can use schedule for 2nd scenario, check this link

Add Business Days 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

@tilekarnilesh 

You can use before insert Business rule on sc_task

Condition: current.request_item.cat_item.name == 'Your Item Name'

how are you creating the catalog task?

If you are using workflow then you can use advanced script in "Catalog Task activity" and script like this

If you are using flow then you can use inline f(x) script for this.

I believe I have answered your question and you can take it further from here.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

@tilekarnilesh 

is that a field or variable?

whatever it may be you can use that in your BR script and then have your logic

var fieldValue = current.request_item.fieldName;
var ritmRecord = current.request_item.getRefRecord();
var variableValue = ritmRecord.variables.variableName;

// now you have value and you can have your own logic
if (variableValue == 'Standard') {
    var nowTime = new GlideDateTime();
    nowTime.addDaysUTC(5);
    current.due_date = nowTime;
} else {
    // some other logic
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

@tilekarnilesh 

I already shared the logic for above on how to access the variable value

AnkurBawiskar_1-1745852768905.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@tilekarnilesh 

you can use this script for 1st scenario to add 5 days

var nowTime = new GlideDateTime();
nowTime.addDaysUTC(5);
current.due_date = nowTime;

you can use schedule for 2nd scenario, check this link

Add Business Days 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur BawiskarIt's okay to use a Business Rule for the first scenario on the sc_task table, with the condition set to 'after insert or update', and scoped to a particular catalog item

@tilekarnilesh 

You can use before insert Business rule on sc_task

Condition: current.request_item.cat_item.name == 'Your Item Name'

how are you creating the catalog task?

If you are using workflow then you can use advanced script in "Catalog Task activity" and script like this

If you are using flow then you can use inline f(x) script for this.

I believe I have answered your question and you can take it further from here.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thankss..