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

SumanthDosapati
Mega Sage
Mega Sage

Hi,

Can you click ctrl+shift+i and see what is the error in your console

 

Regards,
Sumanth

Sumanth the browser error has been fixed. The problem know is that the script is displaying the sysid for the manufacturer instead of the display field.

find_real_file.png

Update you catalog variable 'manufacturer' to reference type of variable.

Looks like you marked your own answer as correct.

 

Mark as correct and helpful if it solved your query.
Regards,
Sumanth