how to auto populate fields from cmdb_ci table based on selected value

Kamer Taj
Mega Expert

I have a scenario like on change of field called   server name ,I need to auto populate fields like IP Address,Operating System,Country e.t.c

I have tried with client script and script include but i need to use for array,

client script:

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

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

  return;

  }

  var servername=g_form.getValue('name_of_the_server_affected_ci');

  var ga=new GlideAjax('ServerDetails');

  ga.addParam('sysparm_name',"serverDetails");

  ga.addParam('sysparm_server',servername);

  ga.getXMLWait();

  var values=ga.getAnswer();

  alert(values);

  g_form.setValue('ip_address',values);

}

Script Include:   name :ServerDetails

var ServerDetails = Class.create();

ServerDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

  serverDetails: function() {

  var ip;

  var server= this.getParameter('sysparm_server');

  var gr=new GlideRecord('cmdb_ci');

  gr.addQuery('sys_id',server);

  gr.query();

  gs.addInfoMessage(gr.getRowCount());

  while(gr.next()){

  ip=gr.getDisplayValue('ip_address');

  gs.addInfoMessage(ip);

  }

  return ip;

  }

});

This code is working for populatin IP address,I need to auto populate remaining fields aswell,How to do with array? so that i can get multiple fields.

3 REPLIES 3

karthiknagaramu
Kilo Sage

Hi,



Look for the sample "Returning multiple values" in the docs


Examples of asynchronous GlideAjax



Regards,


Karthik


Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi kamertaj,



I wrote a blog post about this for a while ago. Take a look here and if you got any questions, just ask.


Lets make GlideAjax a little more dynamic



//Göran


Harish KM
Kilo Patron
Kilo Patron