Autopopulate date time field to today + 10 business days using Business rule

sooriyakala
Tera Contributor

Hi All,

I have to auto populate a date time field(due date) in problem Task form when the short description is "RCA" .The date should be current day + 10 Business days.

 

1 ACCEPTED SOLUTION

okay. what i understand is you want to set the short description and due date both when you are going to create a PR, in that case after Insert BR should help, please check if this helps. 

 

(function executeRule(current, previous /*null when async*/) {

// Add your code herevar gdt = new GlideDateTime();
var gdt = new GlideDateTime();
if(gdt.getDayOfWeekLocalTime() == 6)
gdt.addDaysLocalTime(13);
else if(gdt.getDayOfWeekLocalTime() == 7)
gdt.addDaysLocalTime(12);
else //else add 14 days
gdt.addDaysLocalTime(14);

current.due_date = gdt.getDisplayValue();
current.short_description = 'Root Cause Analysis';

})(current, previous);

 

with the condition given like when the priority is high in condition builder:

find_real_file.png

 

 

 

View solution in original post

14 REPLIES 14

Hi Shishir,

 

when a problem is created with Priority high it should create a problem task and the short description should be "Root Cause Analysis" and Due date should be current day + 10 Business days. So I wrote the client script OnLoad also I removed the condition when short description is  "Root Cause Analysis" and tried your script even then it is not working.Please helpfind_real_file.png

find_real_file.png

find_real_file.png

okay. what i understand is you want to set the short description and due date both when you are going to create a PR, in that case after Insert BR should help, please check if this helps. 

 

(function executeRule(current, previous /*null when async*/) {

// Add your code herevar gdt = new GlideDateTime();
var gdt = new GlideDateTime();
if(gdt.getDayOfWeekLocalTime() == 6)
gdt.addDaysLocalTime(13);
else if(gdt.getDayOfWeekLocalTime() == 7)
gdt.addDaysLocalTime(12);
else //else add 14 days
gdt.addDaysLocalTime(14);

current.due_date = gdt.getDisplayValue();
current.short_description = 'Root Cause Analysis';

})(current, previous);

 

with the condition given like when the priority is high in condition builder:

find_real_file.png

 

 

 

Hi,

 

find_real_file.png

 

And write code in advance section

10 Business Day includes saturday and sunday. So total days to be added 10+2=12

Now get today day if it is saturday then add 1 more days i.e. 12+1=13. If it is non saturday and sunday then add 2 more day.12+2=14. If it is sunday then add days 12.

 

Below is code

 

var gdt = new GlideDateTime();


if(gdt.getDayOfWeekLocalTime() == 6) //if it's Saturday let's add 13 days
    gdt.addDaysLocalTime(13);
else if(gdt.getDayOfWeekLocalTime() == 7) //if it's Sunday let's add 14 days
     gdt.addDaysLocalTime(12);
else //else add 14 days
   gdt.addDaysLocalTime(14);


current.due_date=gdt.getDisplayValue();

 

Thanks

 

After insert is working perfect 🙂 Thanks Upender