The CreatorCon Call for Content is officially open! Get started here.

Populate error message in HR Agent workspace

Shashic
Tera Contributor

Hi Community, 

 

Am trying to limit HR case creation from HR agent workspace(create case). I created a before insert business rule and validating current logged in user. if user belongs to a specific group then hr case should be created otherwise it should throw an error message and stops to insert new case in target table. it works fine in native but error message is not populated on current screen(workspace) when it aborts and shows a pop up immediately. Below is the business rule created. Please can someone assist on this? 

 

script:

(function executeRule(current, previous /*null when async*/ ) {
    var loggedInUser = gs.getUserID();
    var targetGroup = gs.getProperty('sn_hr_le.hrsd_groups');
 
    // Check if the logged-in user is a member of the target group
    var userGroupMember = new GlideRecord('sys_user_grmember');
    userGroupMember.addQuery('user', loggedInUser);
    userGroupMember.addQuery('group', targetGroup);
    userGroupMember.query();
 
    if (!userGroupMember.next()) {
          gs.addErrorMessage('You are not authorized to create case for the selected service.');
        current.setAbortAction(true);
    }
 
})(current, previous);Shashic_0-1761123366944.png

 

1 REPLY 1

MK_SN
Tera Expert

Hi @Shashic ,

 

Business rules in Agent Workspace sometimes execute under the user session context rather than admin context, so when your script runs GlideRecord queries (like sys_user_grmember), ACLs can block it.

 

Instead of using: var userGroupMember = new GlideRecord('sys_user_grmember');

Use: gs.getUser().isMemberOf();

 

Here's your update script:

 if (!gs.getUser().isMemberOf(targetGroup)) {
gs.addErrorMessage('You are not authorized to create a case for the selected service.');
current.setAbortAction(true);
}

 

If my response helped, please mark it as the accepted solution so others can benefit as well.

Thanks,

MK