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

Chander Bhusha1
Tera Guru

Hi Wendy,

Update the script as:

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

var dat = new GlideDateTime(current.warranty_expiration);
dat.addDays(30);


current.retirement_date = dat.getDisplayValue();

})(current, previous);

Mark helpful and correct if it helps.

Thanks,

CB

Thanks so much. Do you know how i can update the background script to update the ones in the system for a one time update?

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

while (gr.next()) {
gr.setValue('retirement_date', gr.getValue('warranty_expiration'));
gr.update();}

You can do all records in scripts - background like this (assuming your encoded query is correct)

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

while (gr.next()) {
  var gdt = new GlideDateTime(current.warrant_expiration);
  gdt.addDaysLocalTime(30);
  gr.setValue('retirement_date', gdt.getDisplayValue());

  gr.update();
}

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();


}