Business Rule - Help with update script.

Lisa Goldman
Kilo Sage

Hello,

The following Business Rules should update the short descript with description.  Please help review the code.  Thanks

Business Rule: After and Update:

 

 

   
     
var catalogItem = new GlideRecord('sc_cat_item');
        if (catalogItem.get('sys_id', current.getUniqueValue)) {

            // Update the catalog item
            catalogItem.short_description = current.description; // Update with the desired field to be updated
            catalogItem.update();
        }

})(current, previous);
6 REPLIES 6

Maddysunil
Kilo Sage

@Lisa Goldman 

Please try below code:

 

(function executeRule(current, previous) {
    // Check if the description field has changed
    if (current.description != previous.description) {
        // Get the catalog item record
        var catalogItem = new GlideRecord('sc_cat_item');
        if (catalogItem.get('sys_id', current.getValue('cat_item'))) {
            // Update the short description with the description field value
            catalogItem.short_description = current.description;
            // Update the catalog item record
            try {
                catalogItem.update();
                gs.info('Short description updated for catalog item ' + catalogItem.sys_id);
            } catch (ex) {
                gs.error('Error updating short description for catalog item ' + catalogItem.sys_id + ': ' + ex);
            }
        } else {
            gs.error('Catalog item not found with sys_id: ' + current.getValue('cat_item'));
        }
    }
})(current, previous);

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Sumanth16
Kilo Patron

Hi @Lisa Goldman ,

 

 

(function executeRule(current, previous /*null when async*/ ) {

  current.short_description = current.request_item.cat_item.name + current.request_item.variables.joiner_name;

})(current, previous);

 

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda