- 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:31 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 01:24 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 01:30 PM
Yep didn't like that at all.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 01:21 PM
use addDaysLocalTime() or addDaysUTC()
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 01:34 PM
Do you know how i can do a one time background script to do the records out there? TIA