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

Seems to be a repeat of an earlier request. The above script I provided didn't work?

I got an error on it

 


Evaluator: org.mozilla.javascript.EcmaError: Cannot read property "warranty_expiration" from null
   Caused by error in script at line 6

      3: gr.query();
      4: 
      5: while (gr.next()) {
==>   6:   var gdt = new GlideDateTime(current.warranty_expiration);
      7:   gdt.addDaysLocalTime(30);
      8:   gr.setValue('retirement_date', gdt.getDisplayValue());
      9: 

can you try now. as you are on background script, current object will not work. 

 

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


}

Thank you so much that worked