- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2019 10:58 PM
I am trying to populate a computer name associated with a user using a variable, once the reference field is added with the persons name the next field which is list of assets should populate with computer names of that specific user. Not the logged in user. I assume i am needing a catalog client script? What would the script be??
The variable for logged on behalf of user is: requested_for
and computer name ref: list_of_assets_stolen
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 04:23 AM
If still, it doesn't help you. please refer to the below article for auto-population.
https://community.servicenow.com/community?id=community_article&sys_id=74ccee25dbd0dbc01dcaf3231f9619bd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 02:11 AM
Its not working or populating the computer name for any user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 03:50 AM
Hi ,
Please try the below code:
Script Includes:
var test = Class.create();
test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
fn_getHostName:function(){
var hostName = '';
var reqFor = this.getParameter('sysparm_user');
var ciRec = new GlideRecord('cmdb_ci_computer');
ciRec.addQuery('assigned_to',reqFor);
ciRec.addQuery('sys_class_name','cmdb_ci_computer');
//ciRec.setLimit(1);
ciRec.orderByDesc('sys_updated_on');
ciRec.query();
/*while(ciRec.next()){
hostName = ciRec.name+','+hostName;
}
hostName = hostName.slice(0,hostName.length-1);*/
if(ciRec.next()){
hostName = ciRec.name;//return the latest updated hostname
}
return hostName;
},
Client script: OnChange
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('test');
ga.addParam('sysparm_name','fn_getHostName');
ga.addParam('sysparm_user',newValue);
ga.getXMLAnswer(fn_callBack,null,null);
function fn_callBack(answer){
g_form.setValue('host_name',answer); //host_name = variable
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 04:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 04:19 AM
Please check whether the script is closed correctly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 04:23 AM
If still, it doesn't help you. please refer to the below article for auto-population.
https://community.servicenow.com/community?id=community_article&sys_id=74ccee25dbd0dbc01dcaf3231f9619bd