- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2025 10:21 PM
script include:
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2025 05:39 PM
@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
08-27-2025 05:39 PM
@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
08-27-2025 08:51 PM
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
08-28-2025 08:10 PM
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
08-27-2025 08:59 PM
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