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 from record producer field date (X days before date)?

Community Alums
Not applicable

Hi Team,

I have a date field on a record producer, and what I would like to achieve is to set the due date on the created ticket 5 days before the date field on the record producer.

I attempted this through a business rule script -

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

	var sd = new GlideDateTime();
	sd.setValue('rec_prod_field_name');
	sd.addDaysUTC(-5);
	current.due_date=sd.getDisplayValue();

})(current, previous);

Can someone please advise the best way to do this and how?!

Thanks,
Alex

1 ACCEPTED SOLUTION

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Alex ,

You can try the below Code :  

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

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

sd.addDaysUTC(-5);

current.due_date=sd.getDisplayValue();

})(current, previous);

 

Please mark my answer as Correct/Helpful based on impact.

 

Regards,

Gunjan Kiratkar

   


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

5 REPLIES 5

Community Alums
Not applicable

Thanks you! 🙂