addDays function not working correctly

sndev1099
Giga Expert

Hi, 

I have created an after business rule on the issue table with the following conditions:

Materiality rating (on associated control) = high
Status (on associated control) = non compliant

My code:

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

var date = new GlideDateTime();
date = current.start_date;
date.addDays(25);
current.end_date=date;
}
)(current, previous);

All I'm wanting to do is add 25 days to the planned end date field on the issue. Can anybody point out what I'm doing wrong?

Thanks

 

1 ACCEPTED SOLUTION

Ahhh Scoped app of course, addDays will not work on that.

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

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

View solution in original post

8 REPLIES 8

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Below code is working for me (just tested this on a after BR on change request):

var date = new GlideDateTime(current.start_date); 
date.addDays(25);
current.end_date = date;
current.update();

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

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Hi Mark. Thanks for your quick response. Still no luck unfortunately. 

 

Could it be that my conditions are incorrect? I'm dot walking to the Item (control) to get the fields.

find_real_file.png

Hello Bracken,

Try removing conditions and test it. Also add logs to check BR is running or not.


Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
 

Thank you,
Abhishek Gardade

I can't tell where these conditions are coming from / if these are correct. For example, maybe the Control is empty? Though you could start the script with a log statement. For example:

gs.info('BR Test');

Then check if this is written in the system log. If not, did not trigger.

There are more debugging options, like the script debugger, though I don't know how experianced you are.

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

Have you also checked the other When to run fields? Like is this on Update? Or on insert? Etc..

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn