- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 03:43 AM
In Servicenow there is this OOTB Script Include named "UserGroup" (api name "global.UserGroup"), which takes as input a UserID and returns the ID's of the groups this user is member of.
I have these variables u_utente_da_copiare (Reference to sys_user) and u_gruppi_da_copiare
(List collector to sys_user_group) in a form on a Catalog Item.
I am trying to set the u_gruppi_da_copiare value to the one returned from the above Script Include function when the field u_utente_da_copiare changes value but this Catalog Client Script i created seems not to work (it does not even show the alert box).
This is the code :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Reset the List Collector field
alert('ciao');
g_form.setValue('u_gruppi_da_copiare', '');
var ga = new GlideAjax('global.UserGroup');
ga.addParam('sysparm_name', 'getGroups');
ga.addParam('sysparm_userSysID', newValue);
ga.getXMLAnswer(function(response) {
if (response) {
var groupIDs = response.split(',');
var filter = 'sys_idIN' + groupIDs.join(',');
// Use setFilter instead of setAdvancedReferenceQual in Service Catalog
g_form.setFilter('u_gruppi_da_copiare', filter);
}
});
}
Could anyone tell me what i'm doing (obviously) wrong?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 04:07 AM
don't set the filter & don't use any client script.
It won't work in portal side.
Use advanced ref qualifier on list collector and show groups for the user selected like this
javascript: 'sys_idIN' + new global.ArrayUtil().convertArray(gs.getUser().getUserByID(current.variables.u_utente_da_copiare).getMyGroups());
In the variable attributes add this
ref_qual_elements=u_utente_da_copiare
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
02-05-2025 04:07 AM
don't set the filter & don't use any client script.
It won't work in portal side.
Use advanced ref qualifier on list collector and show groups for the user selected like this
javascript: 'sys_idIN' + new global.ArrayUtil().convertArray(gs.getUser().getUserByID(current.variables.u_utente_da_copiare).getMyGroups());
In the variable attributes add this
ref_qual_elements=u_utente_da_copiare
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
02-05-2025 05:40 AM
Hi @Ankur Bawiskar , thank you very much, your response was correct so i marked it but i would like to ask this thing too:
all i wanted was populating the list collector field u_gruppi_da_copiare with the groups memberships of the user with id u_utente_da_copiare but my script was setting the filter instead 😅
What is the correct way to do what i really want to?
Regards
Fotios
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 07:10 AM
you should call that script include from advanced ref qualifier and pass the user
Also ensure the variable attribute is set so that the list collector picks the latest user value
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
03-05-2025 10:46 PM
Hii Ankur it was very helpful
Its working very good