- 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
08-29-2024 04:22 AM
Hi @Shakeel Shaik I have same scenario but need to make that filed read only with that aupopulated list how should I achive that ? Can u please guide .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2022 01:55 AM
Demo:-
I have 4 users whose manager is Abel Tuter.
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 03:41 AM
Hello,
If my answer helped you can you also mark it as correct.
Thanks.