how to auto populate fields from cmdb_ci table based on selected value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2017 01:59 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2017 02:14 AM
Hi,
Look for the sample "Returning multiple values" in the docs
Examples of asynchronous GlideAjax
Regards,
Karthik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2017 02:15 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2017 02:18 AM
Use Json as example showed here
https://fruitionpartners.eu/blog/2015/11/17/glideajax-return-multiple-values-using-json/
Harish