Help with Business Rule to add +30 days to a date field

Wendy Peterson
Giga Guru

How can i update this Business Rule to add 30 days to it??? TIA I also have a script include ClientDateTimeUtils I just didn't know how to write it.

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

current.retirement_date = current.warranty_expiration;

})(current, previous);
1 ACCEPTED SOLUTION

var gr = new GlideRecord('alm_hardware');
gr.addEncodedQuery('model_category=81feb9c137101000deeabfc8bcbe5dc4^retirement_dateISEMPTY^warranty_expirationISNOTEMPTY');
gr.query();

while (gr.next()) {

var gdt = new GlideDateTime(gr.warranty_expiration);
gdt.addDaysLocalTime(30);

gr.setValue('retirement_date', gdt.getLocalDate());
gr.update();


}

View solution in original post

13 REPLIES 13

Just a quick note, consider putting script in a community post using this icon: 

find_real_file.png

It makes it easier for readers to read, and copies to copy. 🙂

Hi Wendy,

In the Background Script you can do it :

Remove setLimit If the testing is done just added to updaate only 3 record for testing

var gr = new GlideRecord('alm_hardware');
gr.addEncodedQuery('model_category=81feb9c137101000deeabfc8bcbe5dc4^retirement_dateISEMPTY^warranty_expirationISNOTEMPTY');
gr.setLimit(3);//Testing with 3 records
gr.query();

while (gr.next()) {
var dat = new GlideDateTime(gr.warranty_expiration);
dat.addDays(30);
gr.setValue('retirement_date', dat.getDisplayValue());
gr.update();


}

 

Mark helpful and correct if it helps.

Thanks,

CB

Yep didn't like that at all.

Harsh Vardhan
Giga Patron

 

use addDaysLocalTime() or addDaysUTC()

https://developer.servicenow.com/dev.do#!/reference/api/orlando/server_legacy/c_GlideDateTimeAPI#r_G...

 

script:

 

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

var gdt = new GlideDateTime(current.warranty_expiration);
gdt.addDaysLocalTime(30);

current.retirement_date = gdt.getLocalDate();

})(current, previous);

Do you know how i can do a one time background script to do the records out there? TIA