- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2019 05:29 AM
Is there a way that i can run a business rule from a background script to modify records that were skipped on insert:
(function executeRule(current, previous /*null when async*/) {
var manufacturer=current.company.getValue('sys_id');
var warranty;
var warranty2;
var warrantydate;
var gr = new GlideRecord("u_manufacturer_warranty");
gr.addQuery('u_manufacturer',manufacturer);
//gr.addQuery('u_model',manufacturer);
gr.query();
while(gr.next()) {
warranty = gr.u_warranty_period.dateNumericValue();
warranty2 = (warranty/1000);
warrantydate = new GlideDateTime(current.install_date.getDisplayValue());
warrantydate.addSeconds(warranty2);
}
current.warranty_expiration = warrantydate;
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2019 05:40 AM
Take the core of your script and loop around it. You can even use 'current' as the record name. Something like this:
var current = new GlideRecord("YOURTABLEHERE");
// Add queries to current
current.query();
while (current.next()) {
var manufacturer=current.company.getValue('sys_id');
var warranty;
var warranty2;
var warrantydate;
var gr = new GlideRecord("u_manufacturer_warranty");
gr.addQuery('u_manufacturer',manufacturer);
//gr.addQuery('u_model',manufacturer);
gr.query();
while(gr.next()) {
warranty = gr.u_warranty_period.dateNumericValue();
warranty2 = (warranty/1000);
warrantydate = new GlideDateTime(current.install_date.getDisplayValue());
warrantydate.addSeconds(warranty2);
}
current.warranty_expiration = warrantydate;
current.update(); // DON'T FORGET TO ADD THIS!
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2019 05:36 AM
Hi,
If you can loop through records that were skipped on insert, in a background script, then you should be able to run the same script for these records in the background.
Copy the same script and instead of current just use the glide object of those records.
-Anurag

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2019 05:40 AM
Hi,
Instaed of using current object you can put sys id in script as below in background script
(function executeRule(current, previous /*null when async*/)
{
var manufacturer='sys_id'; // var warranty;
var warranty2; var warrantydate;
})(current, previous);
Thanks,
Trupti S.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2019 05:40 AM
Take the core of your script and loop around it. You can even use 'current' as the record name. Something like this:
var current = new GlideRecord("YOURTABLEHERE");
// Add queries to current
current.query();
while (current.next()) {
var manufacturer=current.company.getValue('sys_id');
var warranty;
var warranty2;
var warrantydate;
var gr = new GlideRecord("u_manufacturer_warranty");
gr.addQuery('u_manufacturer',manufacturer);
//gr.addQuery('u_model',manufacturer);
gr.query();
while(gr.next()) {
warranty = gr.u_warranty_period.dateNumericValue();
warranty2 = (warranty/1000);
warrantydate = new GlideDateTime(current.install_date.getDisplayValue());
warrantydate.addSeconds(warranty2);
}
current.warranty_expiration = warrantydate;
current.update(); // DON'T FORGET TO ADD THIS!
}