- 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
@Rafael Batistot The error is unrelated and seems to be coming from some script include being called in your script.
can you explain bit on below line of code:
var groupName = utils.getGroupName(grupoSysId);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I forgot to remove this part of code, this is no relevant, I use to get the name of group to use in another situation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Rafael Batistot This is part of catalog item and also as per the question, this script is in BR. so are you running this on RITM/Task table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
share the complete script
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