- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2024 08:23 AM
Hello Gents,
I need your knowledge on this.
We have application services in our platform. We need to bring couple of data that we have in the Application service into the related mapped servers. We basically need to run it weekly. I started with this script. But need your help to figure out the ideal way.
// To load all the application service data which we have the data
var rel = new GlideRecord('cmdb_rel_ci');
rel.addQuery('parent.sys_class_name=cmdb_ci_service_auto');
rel.addQuery('parent.u_temp_criticality!=^ORparent.u_business_value!=');
rel.addQuery('child.sys_class_name=cmdb_ci_win_server^ORchild.sys_class_name=cmdb_ci_unix_server');
rel.query();
//gs.info("Total records: "+rel.getRowCount());
//As per the above query, I got the list of records that we need to update via the scheduled job. Now I need to figure out how to update each service-related data in the mapped server.
Below is the fields that I need to bring from the app service into mapped server.
1.u_temp_criticality
2.u_business_value
3.u_reviewed_count
var server = new GlideRecord('cmdb_ci_server'); // query the server table to load the data that we need to update.
server.addQuery('sysclass_name=cmdb_ci_win_server^ORsys_class_name=cmdb_ci_unix_server');
..............
Appreciate your support.
Thanks,
P
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 02:11 AM
Hello @pawan2 ,
Try with the below once.
// Step 1: Load all the application service data
var rel = new GlideRecord('cmdb_rel_ci');
rel.addQuery('parent.sys_class_name', 'cmdb_ci_service_auto');
rel.addQuery('parent.u_temp_criticality', '!=', '');
rel.addQuery('parent.u_business_value', '!=', '');
rel.addQuery('child.sys_class_name', 'IN', 'cmdb_ci_win_server,cmdb_ci_unix_server');
rel.query();
// Step 2: Loop through each relationship and update the child server
while (rel.next()) {
var parentService = rel.parent.getRefRecord(); // Get the parent application service
var childServer = rel.child.getRefRecord(); // Get the child server
// Only proceed if both parent service and child server records are valid
if (parentService.isValidRecord() && childServer.isValidRecord()) {
// Step 3: Update the server with data from the application service
childServer.u_temp_criticality = parentService.u_temp_criticality;
childServer.u_business_value = parentService.u_business_value;
childServer.u_reviewed_count = parentService.u_reviewed_count;
// Update the child server record
childServer.update();
}
}
// Log the completion of the script
gs.debug('Application service data has been updated for mapped servers.');
Please Mark My Answer as Helpful and Accept as Solution, if you find this article helpful or resolves your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 09:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 02:11 AM
Hello @pawan2 ,
Try with the below once.
// Step 1: Load all the application service data
var rel = new GlideRecord('cmdb_rel_ci');
rel.addQuery('parent.sys_class_name', 'cmdb_ci_service_auto');
rel.addQuery('parent.u_temp_criticality', '!=', '');
rel.addQuery('parent.u_business_value', '!=', '');
rel.addQuery('child.sys_class_name', 'IN', 'cmdb_ci_win_server,cmdb_ci_unix_server');
rel.query();
// Step 2: Loop through each relationship and update the child server
while (rel.next()) {
var parentService = rel.parent.getRefRecord(); // Get the parent application service
var childServer = rel.child.getRefRecord(); // Get the child server
// Only proceed if both parent service and child server records are valid
if (parentService.isValidRecord() && childServer.isValidRecord()) {
// Step 3: Update the server with data from the application service
childServer.u_temp_criticality = parentService.u_temp_criticality;
childServer.u_business_value = parentService.u_business_value;
childServer.u_reviewed_count = parentService.u_reviewed_count;
// Update the child server record
childServer.update();
}
}
// Log the completion of the script
gs.debug('Application service data has been updated for mapped servers.');
Please Mark My Answer as Helpful and Accept as Solution, if you find this article helpful or resolves your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 09:13 AM
Thanks a lot for the prompt support Appanna. Let me give it a try quickly. Much appreciated 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 09:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 11:16 PM