Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to fetch OT asset name from cmdb_ci table through scripting ?

Jyoti Mehta
Tera Contributor

Hi,

i have a requirement where i need to fetch OT asset display name/name from cmdb_ci table based on site value and then the value which will be returned that i need to set on catalog item variable.

I have created a script include and catalog client script but unfortunately getting blank value from cmdb_ci table.

Thanks in advance for your help!

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@Jyoti Mehta Could you please post your catalog client script and script include script here. This will enable us to make right suggestions.

Hi Sandeep,

 

Please find details below:

function created in script include: 

getOTAssetname:function(){

        var sysidofsite = this.getParameter('sysparm_value');
        var gr1 = new GlideRecord('cmdb_ci');
        gr1.addQuery('sys_id',sysidofsite);
        gr1.query();
    if(gr1.next()){
           return gr1.ot_display_name;
    }
 
catalog client script:
var sitedetails = g_form.getValue('site'); // will return site sys_id
var ga=new GlideAjax('AutoPopulate_OTSite');
    ga.addParam('sysparm_name','getOTAssetname');
    ga.addParam('sysparm_value',sitedetails);
    ga.getXML(callback);
    function callback(response){
        var answer = response.responseXML.documentElement.getAttribute('answer');
        g_form.setValue('ot_asset',answer);
    }
 
Example record: below is the screenshot of one example OT asset record where on the basis of site i want OT display name then set ot display name in ot_asset variable on catalog item or if there will be multiple record for one site then it will show in drop down list.
JyotiMehta_0-1705687979550.png

 

@Jyoti Mehta Could you please update your script include method as follows and let me know if it works.

getOTAssetname:function(){

        var sysidofsite = this.getParameter('sysparm_value');
        var gr1 = new GlideRecord('cmdb_ci');
        gr1.addQuery('sys_id',sysidofsite);
        gr1.query();
    if(gr1.next()){
           return gr1.getValue('ot_display_name');
    }

Hope this helps.

 

Hi Sandeep,

I have tried this script but still it is not working.