Help with a Business Rule for Populating a Field on an Asset
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2023 07:16 AM - edited ‎08-29-2023 09:12 AM
I have 2 values as shown below on the task table. I need it to look at field #1 and look at the 'do not wipe' true/false field on the Replacement Serial Record and if it's True to populate that same value on #2 the Asset Record. Any ideas on how do to this in a Business Rule when the Asset is populated? which comes from our Vendor.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2023 09:44 AM
Something like this ?
(function executeRule(current, previous /*null when async*/) {
// Check if the Asset field is populated
if (current.u_asset) {
// Retrieve the Replacement Serial Record based on field #1
var replacementSerial = new GlideRecord('your_replacement_serial_table');
if (replacementSerial.get('your_field_1', current.your_field_1)) {
// Check the "do not wipe" field on the Replacement Serial Record
if (replacementSerial.do_not_wipe) {
// Update field #2 (Asset) on the Task Record
current.u_asset = true; // Set to true or any other appropriate value
}
}
}
})(current, previous);
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2023 05:51 AM
I am confused on this - I tried to update that and didn't work. This would on a before insert/update right?
(function executeRule(current, previous /*null when async*/) {
// Check if the Asset field is populated
if (current.u_asset) {
// Retrieve the Replacement Serial Record based on field #1
var replacementSerial = new GlideRecord('alm_hardware');
if (replacementSerial.get('u_do_not_wipe', current.u_replacement_serial)) {
// Check the "do not wipe" field on the Replacement Serial Record
if (replacementSerial.u_do_not_wipe) {
// Update field #2 (Asset) on the Task Record
current.u_asset = true; // Set to true or any other appropriate value
}
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2023 06:10 AM
Yes, "before insert/update" Business Rule would be more appropriate in this case because you want to make changes to the current record before it's inserted or updated.
(function executeRule(current, previous /*null when async*/) {
// Check if the Asset field is populated
if (current.u_asset) {
// Retrieve the Replacement Serial Record based on field #1
var replacementSerial = new GlideRecord('alm_hardware');
if (replacementSerial.get('u_replacement_serial', current.u_asset)) {
// Check the "do not wipe" field on the Replacement Serial Record
if (replacementSerial.u_do_not_wipe) {
// Update field #2 (Asset) on the Task Record
current.u_asset = true; // Set to true or any other appropriate value
}
}
}
})(current, previous);
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar