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

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @Lisa Goldman ,

 

What you are missing is >  getUniqueValue();

SohailKhilji_0-1711790050635.png

 

 

Or simply copy this code inside your business rule ...:

 

var item = current.getUniqueValue();

var catalogItem = new GlideRecord('sc_cat_item');
catalogItem.addQuery('sys_id', item );
catalogItem.query();
if(catalogItem.next())
 {
            catalogItem.short_description = current.description; 
            catalogItem.update();
}

 

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Good morning @Sohail Khilji 

Thank you for pointed out my mistake.  I copied the exactly code you provided and it is still not working. What have I done wrong?

LisaGoldman_0-1711809414609.pngLisaGoldman_1-1711809456247.png

 

Hi @Lisa Goldman ,

 

try this code:

var catalogItem = new GlideRecord('sc_cat_item');
catalogItem.addQuery('sys_id', current.sys_id );
catalogItem.query();
if(catalogItem.next())
 {
            catalogItem.short_description = current.description; 
            catalogItem.update();
}

☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Appanna M
Tera Guru

Hello @Lisa Goldman ,

Can you confirm the table name for the BR?

Try the below code:

 

 

(function executeRule(current, previous /*null when async*/ ) {
//Add your code here
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);
 7 Views