- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 01:41 AM
Hi there
i have a list collector (sys_user) field on a catalog item.
i need to get the 'employee_number' which is field on the sys_user table and store the values as a comma separated list on a single text field 'user_list' on the catalog item.
i have done scripts on refrence fields but never on a list collector
please advise
Thanks
Levino
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('restrictduplicateitem');
ga.addParam('sysparm_name', 'userList');
ga.addParam('sysparm_user', newValue);
ga.getXMLAnswer(function(answer){
var bs = answer;
g_form.setValue('user_list',bs);
}
);
}
//Type appropriate comment here, and begin script below
script include
var restrictduplicateitem = Class.create();
restrictduplicateitem.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userList: function() {
var user = this.getParameter('sysparm_user');
var string = [];
string.split(',');
for (var i = 0; i < string.length; i++) {
var gr = new GlideRecord('sys_user');
gr.get(string[i]);
gr.addQuery('sys_id', user);
gr.query();
while (gr.next()) {
var list = gr.getDisplayValue('getemployee_number');
//list.split(',');
return list;
}
}
},
type: 'restrictduplicateitem'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 04:02 AM
small update
arr.push(gr.getValue('employee_number'));
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 04:41 AM
Glad to help.
Happy learning.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 02:16 AM
Hi @levino
Please try your script like this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('restrictduplicateitem');
ga.addParam('sysparm_name', 'userList');
ga.addParam('sysparm_user', newValue);
ga.getXMLAnswer(function(answer){
var bs = answer;
alert(bs);
g_form.setValue('user_list',bs);
}
);
}
//Type appropriate comment here, and begin script below
script include
var restrictduplicateitem = Class.create();
restrictduplicateitem.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userList: function() {
var user = this.getParameter('sysparm_user');
var string = [];
var list = [];
string.push(user);
//string.split(',');
for (var i = 0; i < string.length; i++) {
var gr = new GlideRecord('sys_user');
//gr.get(string[i]);
gr.addQuery('sys_id', string[i]);
gr.query();
while (gr.next()) {
// var list = gr.getDisplayValue('getemployee_number');
list.push(gr.getDisplayValue('getemployee_number'));
//list.split(',');
return list;
}
}
},
type: 'restrictduplicateitem'
});
Please mark correct or helpful if your issue is resolved.
Regards
Devender
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 04:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 04:31 AM - edited 05-31-2023 05:05 AM
Hi @levino ,
Try replacing below script in script include and let me know if it works:
Script Include:
Amish Ranjan