Help with a Business Rule for Populating a Field on an Asset

Wendy Peterson
Giga Guru

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. 

 

 

2023-08-29_11-06-31.png

 

 

3 REPLIES 3

Tushar
Kilo Sage
Kilo Sage

Hi @Wendy Peterson 

 

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

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

 

 

Hi @Wendy Peterson 

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