- 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 06:31 AM
This is being set to the business rule of the sc_task. It's set to run before insert/update.
when I updated the "D" that was capitalized, now it blanks out the due_date field and shows nothing. Ugh. I can't believe this is giving me this much trouble.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2019 06:42 AM
So what info did the logging give you? Is for example already this one wrong?
gs.info('==> date: ' + current.r_3716_distribute_notice);
At what point does the script fail?
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 06:46 AM
I did test now on my PDI, for example below code does give a correct date minus 1 day:
var gr = new GlideRecord('incident');
gr.get('5649ef93db3c0850ceed9ce8db9619dd');
var gdt = new GlideDateTime(gr.sys_created_on);
gs.info('==> gdt: ' + gdt);
gdt.addDaysLocalTime(-1);
gs.info('==> gdt-1: ' + gdt);
gs.info(gdt);
Is your r_3716_distribute_notice field Date or DateTime?
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 08:49 AM
so found that it's not showing on the debug for business rules unless I add it to run before "query" as well. Once I do that, I can see it and for some reason it's skipping it. I am going to look at the conditions to see why.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2019 09:06 AM