Asset Name Auto Populate

SATYAP
Kilo Contributor

@IN Incident table for a newly created field called Asset Name. How can I auto populate the Asset Name with the corresponding asset from the cmdb_ci_computer table whenever the 'Configuration Item' field is filled.

2 REPLIES 2

Bhavya11
Kilo Patron

Hi @SATYAP ,

 

you can try below ways

 

1. without script and without creating new field : open incident form  right click Configure > form layout  search the Configuration item then click on  expand icon 

Bhavya11_0-1748324627953.png

 then after that it will show all the configuration item fields select the asset push to selected 

Bhavya11_1-1748324690734.png

 

then it will populate the assets whenever you select the cmdb_ci_computer  records in Configuration Item' field.

 

 

2. With Script:

Client script :

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
 var ga = new GlideAjax('GetAssetInfo'); // GetAssetInfois the script include name 
   ga.addParam('sysparm_name','getAssetName'); 
   ga.addParam('sysparm_ci_name',newValue); // set ci value

   /* Call GetUserInfo.managerName() with user set to Fred Luddy and use the callback function ManagerParse() to return the result when ready */
   ga.getXMLAnswer(AssetName);  		
}
function AssetName(response) {  
   g_form.setValue('u_asset_name',response);// newly created field name 'u_asset_name'

}

 

Script include:

 

var GetAssetInfo= Class.create();
GetAssetInfo.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getAssetName: function() {
        var ciName = this.getParameter("sysparm_ci_name");
        var grCi = new GlideRecord('cmdb_ci_computer');
        grCi .get("sys_id", ciName );

        // Build the payload. You can return additional data if needed. 
        var result = {    
           "asset": grCi.getDisplayValue('asset')
        }; 
        return JSON.stringify(result);
    },
    type: 'GetAssetInfo'
});

 

 

If this information proves useful, kindly mark it as helpful or accepted solution.

Thanks,

BK

 

Ankur Bawiskar
Tera Patron
Tera Patron

@SATYAP 

Why do you want this custom field?

2 ways

1) either show dot walked field on from from that reference field

OR

2) create new field and populate using onChange client script

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader