Bulk Update in CSM workspace with impersonate Admin

ValeriaSasina
Tera Contributor

Hi Community,

We got a request for Agents to be  able to bulk update cases in CSM workspace anonymously. Our idea is to have an additional field 'Mass Update Comment' where Agent leaves a comment that will be copied to Additional comment as a System Admin. (We also clear out Mass Update custom field)
Here is a JS for Business Rule (conditions: async on insert/update, when mass_update field changes) 

 

 

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

    // Add your code here
    var adminSysID;
    var grAnonUser = new GlideRecord('sys_user');
    if (grAnonUser.get('user_name', 'admin')) {
        adminSysID =grAnonUser.sys_id.toString();
        
        // Impersonate the admin user
        gs.getSession().impersonate(adminSysID);
        
        var cmt = current.u_mass_update_comment.toString();
        current.comments = cmt;
        current.u_mass_update_comment = '';
        current.setWorkflow(false);
        current.update();
        
        gs.getSession().impersonateOriginalUser();
    
    } else {
        gs.error('Admin user not found');
    }
    
})(current, previous);

Expected behavior when Agent select multiple records (for example 5) > Edit(5) > leaves comment and  click Update - interface shows message '5 records updated successfully' and we see newly added journal entry from System Administrator under Additional comment.
What we experience is the interface randomly throws error message that 2 record updated successfully and 3 records not updated, although we do see newly added journal entry from System Administrator under Additional comment for all 5 records.
I know there is an OOB functionality for bulk updates, might it be throwing the messages?
Please advise what might be the reason for that behavior, or if there is any workaround for it.
Thank you in advance

 

0 REPLIES 0