- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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)
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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