- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2022 01:09 AM
Hello everyone.
I want to autopopulate a list collector (variable name: initial_members) of active users whose manager is in the manager field.
I am new to servicenow and I don't have much knowledge about scripting so I highly appreciate your help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2022 01:46 AM
Hi @Le_Bear
Open your Initial Members variable and go to the Type Specification Tab as shown in the above image.
here the backend value of Manager is manager. Make the necessary changes and add the query in Reference Qualifier.
Thanks,
Shakeel Shaik 🙂
Shakeel Shaik 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2022 02:32 AM - edited 11-27-2022 02:35 AM
Hello,
You can use the below code to auto populate user based on the manager field selected:-
Onchnage Client script on manager field. Just replace your list collector field name:-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// give here the list collector variable name
g_form.clearValue('replacelistcollectorfieldname');
var ajax = new GlideAjax('getAssignGroups');
ajax.addParam('sysparm_name', 'getUserGroups');
ajax.addParam('sysparm_request_for', newValue);
ajax.getXML(populateValues);
}
function populateValues(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// give here the list collector variable name
g_form.setValue('replacelistcollectorfieldname', answer); // Mobile/Portal Compatible
}
Script include with name getAssignGroups and make sure client callabale chekcbox is true
var getAssignGroups = Class.create();
getAssignGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserGroups: function(){
var listGroup = [];
var requester = this.getParameter('sysparm_request_for');
var parm = this.getParameter('sysparm_view');
var jsonArr = [];
var recGrp = new GlideRecord('sys_user');
recGrp.addQuery('manager', requester);
recGrp.query();
while (recGrp.next()) {
listGroup.push(recGrp.sys_id.toString());
}
return listGroup.toString();
},
type: 'getAssignGroups'
});
Now once you select the manager field the list collector will be autopopulated you don't have to select it manually.
Also if you want to learn more about it you can check the below article
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2022 01:46 AM
Hi @Le_Bear
Open your Initial Members variable and go to the Type Specification Tab as shown in the above image.
here the backend value of Manager is manager. Make the necessary changes and add the query in Reference Qualifier.
Thanks,
Shakeel Shaik 🙂
Shakeel Shaik 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2022 01:54 AM
Thank you very much. It is an acceptable answer.
However, I am curious if it is possible to configure in a way so that it will auto select the populated users in the field instead of manually clicking the users.
Like so.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2022 03:51 AM
Hi Shakeel,
I have a question. What if I am basing my list collector on this reference field:
So like if Asia or Western Europe is selected. It will only show the contents related to it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2022 05:06 AM
Hi @MelvinBulan,
You can do it please refer to my above response or if you want the exact solution, then please share the backend values of Table and Fields.
Thanks,
Shakeel Shaik 🙂
Shakeel Shaik 🙂