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.

Need to help to populate cmdb ci storage server fields in hardware assest table

mastanbe
Tera Contributor

Hi All,

I have a requirement that we have 3 fields in cmdb Ci storage server table. Those are primary contact , secondary contact  and responsible manager fields.

These three fields I need to populate on alm_hardware table.

For this I have created 3 new fields but when I need to write script include and call it in onload clientscript.

Can you please help me on this how to write script include and onload client script.

7 REPLIES 7

zeeshan8
Giga Contributor

SCRIPT INCLUDE:

functionname: function() {
        var obj = {};
        var param = this.getParameter("value from client script")
        var gr = new GlideRecord("tablename");
        gr.addQuery("variable",param);
        gr.query();
        if (gr.next()) {
            obj.primary_contact = gr.primary_contact.toString();
            obj.secondary_contact = gr.secondary_contact.toString();
            obj.responsible_manager = gr.responsible_manager.toString();
          
        }
        var json = new JSON();
        return json.encode(obj);
    },

Client script:

function onLoad() {
    var ga = new GlideAjax('scriptinclude name'); 
    ga.addParam('sysparm_name','functionname'); 
    ga.addParam('sysparm_variable', passvariable); 
    ga.getXML(functionanme);

    function functionanme(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        var parseData = JSON.parse(answer);
             
           g_form.setValue("primary_contact", parseData.primary_contact);
            g_form.setValue("secondary_contact, parseData.secondary_contact);
            g_form.setValue("responsible_manager", parseData.responsible_manager);
            

}

hi zeeshan,

Script is working but in list view those fields are not displaying.

Can I use a business rule for this or else in default value of each field in target table how can I call the script include.

Could you please suggest me on this

Click on personalise list> select those fields in slush bucket .

Now you can see in list view. 

Hi prashant

That I was done but the values are not populating on list view. 

Is there any idea to show those values on list view also.