Subtract 1 day from populated due date

booher04
Tera Guru

Afternoon community.  I have a need to populate the due date on SCTASK based off of a date field variable(r_3716_distribute_notice) and then subtract 1 day from that date.  I am trying to use a business rule for this but it's not populating correctly.  I am sure I have something wrong in the code.  I've tried many different codes on my own.

var gdt = current.r_3716_distribute_notice;

if (current.r_3716_distribute_notice){
gdt.gs.daysAgo(1);
task.due_date=gdt;
}

Also tried this:

var gdt = current.r_3716_distribute_notice.getGlideObject();

if (current.r_3716_distribute_notice) {

gdt.subtractDays(1);

current.due_date=gdt;

1 ACCEPTED SOLUTION

dvp
Mega Sage
Mega Sage

Variables is on RITM.. you need to dot walk to ritm first

Here is the updated script

if(current.request_item.variables.r_3716_distribute_notice != undefined){
	var gdt = new GlideDateTime(current.request_item.variables.r_3716_distribute_notice);
	gdt.addDaysLocalTime(-1);
	current.due_date = gdt;
}

View solution in original post

16 REPLIES 16

Ah oke good info!

Looks like the current.r_3716_distribute_notice is already wrong, it's presenting undefined, so the addDays etc will not work. Can you double check the name? Also is it an actual field, or a variable? If variable, try current.request_item.variables.r_3716_distribute_notice

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

rajesh9885
Mega Guru

Please try this

 

current.due_date = gs.nowDateTime();
var duedate= current.r_3716_distribute_notice.getGlideObject();
duedate.addDays(-1);

Thank you for the reply.  It didn't work either.  Very frustrated with this "simple" script.

ccajohnson
Kilo Sage

You mention variable. Are you mapping your scripts to that variable, or to a field on the form. 

current.r_3716_distribute_notice appears to be a field. If this is a variable, you need to go through the variable pool first:

current.variables.r_3716_distribute_notice