- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 10:03 AM
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;
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2019 07:31 AM
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;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 10:12 AM
Hi there,
Have a look at this page:
https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=GCDT-addDays_N
There's a nice example about addDays(-1):
var gcdt = new GlideCalendarDateTime("2011-08-31 08:00:00");
gcdt.addDays(-1);
gs.print(gcdt.getDate());
and
var gdt = new GlideDateTime("2011-08-31 08:00:00");
gdt.addDaysUTC(-1);
gs.info(gdt.getDate());
If your field also in that same date format? If so, your could just use something like:
var gcdt = new GlideCalendarDateTime(current.your_field);
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2019 05:25 AM
One question since I can't get this to work correctly still. Where the var is, they have "2011-08-31 08:00:00". Would I put 11-04-2019 00:00:00? That's our time format.
I've tried using var gcdt = new GlideCalendarDateTime(current.your_field); it didn't seem to do anything either.
var gdt = new GlideDateTime(current.r_3716_distribute_notice);
gdt.addDaysLocalTime(-1);
current.due_Date = gdt;
That is the business rule script I have in place, but it's not working correctly either. I'm not the best scripting so I could be missing some code as well.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2019 05:40 AM
Check if this is oke, I see an uppercase? Guess that's a typo?
current.due_Date
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2019 05:43 AM
If you are executing this code server side, the format of yyyy-mm-dd or yyyy-dd-mm etc doesn't matter.
You could add some log statements to debug or use the debugger.
gs.info('==> date: ' + current.r_3716_distribute_notice);
var gdt = new GlideDateTime(current.r_3716_distribute_notice);
gs.info('==> gdt: ' + gdt);
gdt.addDaysLocalTime(-1);
gs.info('==> gdt-1: ' + gdt);
current.due_date = gdt;
Do al these info statements give what you would expect?
Also, I assume this is a before insert/update business rule?
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