Script to retrieve Manufacturer and Model Id from cmdb_ci_computer

Luis Roman
Kilo Guru

I am trying to retrieve the Model id and the Manufacturer from the cmdb_ci_computer table in a scope application (x_g_lme_ham_classi.getComputerFields).

I have the following script include and client script. Problem not able to retrieve the values to display them in a catalog item. Also getting “There is a browser Javascript error in your console” Any suggestions! Your collaboration and guidance will be appreciated.

Script Include:

var getComputerFields = Class.create();

getComputerFields.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

getcmdb_ci_computerFields : function() {

var serial_number = this.getParameter('sysparm_serial_number');

var standardFields = new GlideRecord('cmdb_ci_computer');

standardFields.addEncodedQuery('serial_number='+serial_number);     

standardFields.query();

if(standardFields.next()) {

return standardFields.manufacturer.getDisplayValue()+ '|' +

standardFields.model_id.getDisplayValue();

}

return '';

},

    type: 'getComputerFields'

});

Catalog Client Script:

 function onChange(control, oldValue, newValue, isLoading) {

   if (isLoading || newValue == '') {

      return;

   }

alert('onChangeSerialNumber'+ newValue);

{

    var vserial_number = newValue;

    alert('onChangeSerialNumber newScript ' + newValue + " = " + vserial_number);

        var ga = new GlideAjax('x_g_lme_ham_classi.getComputerFields');

        ga.addParam("sysparm_name", "getcmdb_ci_computerFields");

        ga.addParam("sysparm_serial_number", vserial_number);

        ga.getXMLAnswer(getResponse);

    }

}

    function getResponse(response) {

        var values =response.toString().split('|');

       g_form.setValue('manufacturer', values[0]);

      g_form.setValue('model', values[1]);

     }

1 ACCEPTED SOLUTION

Kumar appreciate you helping me. Those two fields are reference fields. I try your suggestion and the results are: the manufacturer is displaying the sysid of the reference fields instead of the value.

Any other suggestions, please. OR let me know what additional information I need to provide you.

View solution in original post

7 REPLIES 7

Aman Kumar S
Kilo Patron

Few things to check here:

1. What is the type of manufacturer and model field, Reference or String?
If it is reference, change your script include lines as:

return standardFields.manufacturer.toString()+ '|' +

standardFields.model_id.toString();

OR

If it is string, change your client script line as :

var values =response.split('|');

2. You script include "getComputerFields", check if the "Accessible from" field has been set as "All application scopes"

Best Regards
Aman Kumar

Kumar appreciate you helping me. Those two fields are reference fields. I try your suggestion and the results are: the manufacturer is displaying the sysid of the reference fields instead of the value.

Any other suggestions, please. OR let me know what additional information I need to provide you.

You are getting the sys_ids back, it means your script include is working fine.

Can you check manufacturer field on the catalog form, if the reference is set as core_company table?

Also, if above point is alright, then check for core_company field, if the name field is set as display value.

Best Regards
Aman Kumar

@Luis Roman 

Is your issue resolved?

 

Feel free to mark correct, if your issue has been resolved, so it ends up in solved queue.

Will be helpful for others looking for the similar query.

Best Regards
Aman Kumar