Requirment of CMDB in Record producer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 02:13 AM
Hello Team,
I have one variable called "Application " which refers to cmdb_ci_service_discovered table . on the selection of Application we need to populate the cis runs on that particular application in other variable called server cis .
I have written Script include for this However for me is showing all cis present in cmdb_ci_server table .
script include :-
var Populate_servers_based_on_application_servicies = Class.create();
Populate_servers_based_on_application_servicies.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getServices: function() {
var app_service = this.getParameter('sysparm_sys_id');
//var arr = [];
var ser = new GlideRecord('cmdb_rel_ci');
ser.addQuery('parent.sys_id', app_service);
//ser.addQuery('type', '60bc4e22c0a8010e01f074cbe6bd73c3');
ser.query();
if (ser.next()) {
return ser.child;
} else
{
return "Record Not Found";
}
//return sys_idIN+arr.join(',');
},
// //getenvironment:function()
// {
// var env = new GlideRecord('cmdb_ci_serve')
// }
type: 'Populate_servers_based_on_application_servicies'
});
Client script :-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('Populate_servers_based_on_application_servicies');
ga.addParam('sysparm_name', 'getServices');
ga.addParam('sysparm_sys_id', newValue);
ga.getXML(getServices);
function getServices(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
// var clearvalue; // Stays Undefined
// var returneddata = answer.evalJSON(true);
g_form.setValue("server_ci", answer);
// if (answer == 'Record Not Found') {
// g_form.setMandatory('server_ci', false);
// g_form.setMandatory('environment', false);
// } else {
// g_form.setMandatory('server_ci', true);
// g_form.setMandatory('environment', true);
// }
}
}
Here I am able to populate the cis , but is shows all from the cmdb_ci_Server table .
My Requirement is only related cis needs to be populate on the selection of Application name,.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 04:18 AM - edited 08-13-2024 05:51 AM
It seems like this is a different version/attempt of your scripts then what you described as populating the CIs. I'm not following if you ever had the population working correctly, or if it's only ever populated every server CI. This is what the SI should look like, assuming the selected discovered CI is a parent in the relationship table, and that you are using the value to populate a list field or list collector variable.
var Populate_servers_based_on_application_servicies = Class.create();
Populate_servers_based_on_application_servicies.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getServices: function() {
var app_service = this.getParameter('sysparm_sys_id');
var arr = [];
var ser = new GlideRecord('cmdb_rel_ci');
ser.addQuery('parent', app_service);
ser.addQuery('type', '60bc4e22c0a8010e01f074cbe6bd73c3');
ser.query();
while (ser.next()) {
arr.push(ser.child.toString());
}
return arr.join(',');
},
// //getenvironment:function()
// {
// var env = new GlideRecord('cmdb_ci_serve')
// }
type: 'Populate_servers_based_on_application_servicies'
});
If this isn't giving you the correct list of server sys_ids, add a log (gs.info or gs.addInfoMessage) to the SI to show the sys_id passed in from the client, and use the type sys_id in the filter of a manual list view on the CI Relationship table to make sure you are getting the expected results, then add alerts to the client script to see the value received from the server, etc.