- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
script include:
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
@klbhargav3 Please update your script as follows.
var autopopulateusergroup = Class.create();
autopopulateusergroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUser: function() {
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("user", gs.getUserID());
gr.query();
var grp = [];
while (gr.next()) {
grp.push(gr.group.toString());
}
if (grp.length > 0) {
var user = new GlideRecord("sys_user_grmember");
user.addQuery("group", "IN", grp);
user.query();
var userName = [];
while (user.next()) {
if(userName.indexOf(user.user.toString())==-1)
userName.push(user.user.toString());
}
return "sys_idIN"+userName.join(",");
}
},
type: 'autopopulateusergroup'
});
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
@klbhargav3 Please update your script as follows.
var autopopulateusergroup = Class.create();
autopopulateusergroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUser: function() {
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("user", gs.getUserID());
gr.query();
var grp = [];
while (gr.next()) {
grp.push(gr.group.toString());
}
if (grp.length > 0) {
var user = new GlideRecord("sys_user_grmember");
user.addQuery("group", "IN", grp);
user.query();
var userName = [];
while (user.next()) {
if(userName.indexOf(user.user.toString())==-1)
userName.push(user.user.toString());
}
return "sys_idIN"+userName.join(",");
}
},
type: 'autopopulateusergroup'
});
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
while pushing value into array either use toString() or use getValue()
userName.push(user.getValue('user'));
OR
userName.push(user.user.toString());
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
2 weeks ago
Hope you are doing good.
Did my reply answer your question?
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
2 weeks ago
Corrected Script Include:
var autopopulateusergroup = Class.create();
autopopulateusergroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUser: function() {
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("user", gs.getUserID());
gr.query();
var grp = [];
while (gr.next()) {
grp.push(gr.group.toString());
}
if (grp.length > 0) {
var user = new GlideRecord("sys_user_grmember");
user.addQuery("group", "IN", grp);
user.query();
var userName = [];
while (user.next()) {
// Push the sys_id as string, not the GlideRecord object
userName.push(user.user.toString());
}
// Return proper format for reference qualifier
if (userName.length > 0) {
return userName.join(",");
}
}
// Return empty result if no users found
return "";
},
type: 'autopopulateusergroup'
});
Reference Qualifier:
javascript:new autopopulateusergroup().getUser()
Fixed the return format: Changed from "sys_idIN"+userName.join(",") to just userName.join(",")
Added .toString() to user.user.toString() to ensure you're getting the sys_id string value, not the GlideRecord object