Auto populate computer name

soraya_vally
Mega Guru

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

 

find_real_file.png

1 ACCEPTED SOLUTION

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

View solution in original post

17 REPLIES 17

AirSquire
Tera Guru

Where is the computer name assigned to the user stored? You have to write an onChange Client Script, which will run on Chnage of the User variable.

You can do a GlideAjax call to a Script Include and pass the user selected, i.e., newValue. In the script Include Glide the table where the computer-to-user mapping is stored and the return the computer Name for the selected user.

If you face challenge scripting it, mention the name of the table for computer-to-user mapping. I can provide you with the script

Regards
Air

Hi 

 

I am not much of a scriptor so your help will be greatly appreciated!

 

It sits on cmdb_ci_computer table and the IT Business owner (label) is the person who owns the computer which is assigned_to

 

find_real_file.png

Assumption: List of assets stolen refers to cmdb_ci_computer table

Client Script - onChange of requested_for:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
var abc = new GlideAjax('ComputerAssigned');
	abc.addParam('sysparm_name','getComputer');
	abc.addParam('sysparm_usid',newValue);
	abc.getXML(Fundo);
}
function Fundo(response){
	var answer = response.responseXML.documentElement.getAttribute("answer");
	alert(answer);
        g_form.setValue('list_of_assets_stolen',answer);
}

Script Include - Client callable checked to true. 

var ComputerAssigned = Class.create();
CallerRoles.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getComputer: function(){
	var computer = '';
	var uid = this.getParameter('sysparm_usid');
	var com = new GlideRecord('cmdb_ci_computer');
	com.addQuery('assigned_to',uid);
	com.query();
	if(com.next()){
		computer = com.sys_id;
	}
	return computer;
},
    type: 'ComputerAssigned'
});

Regards
Air

Getting this error on the catalog client script:

 

find_real_file.png

 

Script Include - Client callable checked to true. Assuming your mapping table to be comp_user_map_table. replace it with you table name.

Would i replace it with: cmdb_ci_computer?