Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Set due date 24 hours from created date?

Community Alums
Not applicable

Hi All,

I have a requirement to always set the due date of a specific record producer always to 24 hours after the created date/ always the next day.

How can I achieve this?

Thanks!
Alex

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

why not use record producer script itself and you don't need any extra BR etc?

var gdt = new GlideDateTime();

gdt.addDaysUTC(1);

current.setValue('due_date', gdt.getValue());

Regards
Ankur

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

View solution in original post

8 REPLIES 8

Yousaf
Giga Sage

Hi Alex,

Please try this 

create a business rule on RITM 

when to run : before insert

var createdDate = current.created;
var gr = new GlideDateTime(createdDate);
gr.addDaysLocalTime(1);
var test = gr.toString();
gs.log(test);
current.setValue('u_due_date', test);

 

Or add below line to  Dictionary Entry Default value (Configure Dictionary ->default value)for due_date field

javascript: var d = new GlideDateTime(); d.addDaysLocalTime(1); d.getDisplayValue();



Mark Correct or Helpful if it helps.


***Mark Correct or Helpful if it helps.***

Found your old thread maybe you can try to set 1 day here and try too

Set due date from record producer field date (X days before date)?


***Mark Correct or Helpful if it helps.***

Community Alums
Not applicable

Hi there,

thanks for getting back to me!

What do I replace 'test' with?

Thanks,
Alex

Community Alums
Not applicable

I have tried your script and the below script with no luck -

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

var sd = new GlideDateTime(current.created);  //Write down Variable name instead of 'date_variable_name' from record producer. 

sd.addDaysUTC(1); 

current.due_date=sd.getDisplayValue(); 

})(current, previous);