- 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 02:14 AM
update as this
I hope your script include is client callable
var restrictduplicateitem = Class.create();
restrictduplicateitem.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userList: function() {
var user = this.getParameter('sysparm_user');
var arr = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', 'IN', user);
gr.query();
while (gr.next()) {
arr.push(gr.getDisplayValue('getemployee_number'));
}
return arr.toString();
},
type: 'restrictduplicateitem'
});
Client script
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){
if(answer){
g_form.setValue('user_list', answer);
}
});
}
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
05-31-2023 03:42 AM
Hi Ankur
is this correct
arr.push(gr.getDisplayValue('getemployee_number'));
, i have removed get before employee_number
i put a alert on the client script, it comes back with just answer
not sure if i missing something , yes it client callable
Thanks
Levino
- 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:12 AM
champion Ankur , all your solutions have been 10/10