- 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-04-2019 09:11 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2024 07:40 PM
Could you please help with the below query
Re: How to subtract days from a schedule - ServiceNow Community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2019 05:39 AM
Please try this
current.due_date = gs.nowDateTime();
var duedate= current.r_3716_distribute_notice.getGlideObject();
duedate.addDays(-1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2019 06:32 AM
Thank you for the reply. It didn't work either. Very frustrated with this "simple" script.

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