- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 01:11 PM
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);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 01:24 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 01:15 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 01:21 PM
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();}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 01:24 PM
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();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 01:24 PM
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();
}