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

non-admin try to Add group

Rafael Batistot
Kilo Patron

Hi Team

To add a a group in a specific user i'm using this script. Is not a beauty code, but work 

var users = current.variables.select_the_user.toString().split(",");
var arrayGrupo = current.variables.group_associate.toString().split(",");

users.forEach(function(userSysId) {
    arrayGrupo.forEach(function(grupoSysId) {
        var groupName = utils.getGroupName(grupoSysId);
        addUserGroupWithId(userSysId, grupoSysId);
    });
});

function addUserGroupWithId(userID, groupID) {
        var userGroupGR = new GlideRecord('sys_user_grmember');
        userGroupGR.initialize();
        userGroupGR.user = userID;
        userGroupGR.group = groupID;
        userGroupGR.insert();
    },


i've applicated in a business rule to trigger when a non-admin try to add an user a specific group 

besides not work i'm facing this issue in the log. 

Add user in group(56c2540c470cf610cbcc97a4116d4384): ReferenceError: "item" is not defined. (#0(eval); line 97)


RafaelBatistot_0-1757976503732.png

With Admin works normally, i checked:

ACL,
Business Rule,
Script Include,
UI and DATA polices
Client Script... everything, bot not found 

if anybody got the same problem i would like to hear you. 

Thank's advance

 






 

1 ACCEPTED SOLUTION

Nehal Dhuri
Mega Sage

Hey @Rafael Batistot ,

Is this catalog item meant to add users to a group?
If yes, you can easily achieve this using a Flow. Just make sure the flow’s "Run As" property is set to System User to ensure it has the necessary permissions.

I'm also attaching a screenshot of a similar setup we've implemented.

NehalDhuri_0-1758011070304.png

 

Please hit like and mark my response as correct if that helps

View solution in original post

8 REPLIES 8

@Ankur Bawiskar 

 

This is all the script. I forgot to remove this part: 

var groupName = utils.getGroupName(grupoSysId);

 

but this is not relevant. I get the name of the group to use in other situations 

 

but the ideia is, the user select an user and group, via catalog.  The group is aggregate in the user. Done 

@Rafael Batistot 

request you to share the complete script so that we can help better

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Nehal Dhuri
Mega Sage

Hey @Rafael Batistot ,

Is this catalog item meant to add users to a group?
If yes, you can easily achieve this using a Flow. Just make sure the flow’s "Run As" property is set to System User to ensure it has the necessary permissions.

I'm also attaching a screenshot of a similar setup we've implemented.

NehalDhuri_0-1758011070304.png

 

Please hit like and mark my response as correct if that helps

Hi @Nehal Dhuri 

Your idea resolve my problem, when i try via Flow Designer i'm not get this msg erro for non-admins users. Thank you