
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 05:29 PM
Greetings,
I'm not a scripter. I've dabbled in some very basic stuff, but I am in over my head on this one. LOL
I'm hoping someone out there has a moment to help me with what I think is potentially a very basic script. At least for people who script : )
Background:
I created a custom app to track CMDB Application DR testing. When a DR runbook is excecuted (tested), a user creates a DR Execution Record in the custom app. The Execution Record is associated to the CMDB item based on Runbook name and a Runbook can be associated to multiple apps. When the DR Execution Record is submitted the date it was executed should sync across all CMDB applications using the same runbook.
Requirement:
Within the DR Test Record form (custom table u_dr_test_execution) a user selects a runbook name from the reference field "u_dr_test_execution.u_dr_runbook_executed", then populates the date field "u_dr_test_execution.u_test_date".
Once the rest of the form is completed and submitted, the rule/script should sync the Runbook Execution Date "u_dr_test_execution.u_test_date" with all CMDB applications having the same DR Runbook name value. I'm thinking this should be a Business Rule "after" "update" but could be wrong. Maybe an On Change Client Script?
In essence:
When a DR Test Execution record is created and submitted, the Runbook Execution Date (u_dr_test_execution.u_test_date) value should get pushed to to the Last Failover field (cmdb_ci_appl.u_dr_tested) on all application records where DR Runbook (cmdb_ci_appl.u_dr_runbook) = DR Runbook Executed (u_dr_test_execution.u_dr_runbook_executed)
If it was a one to one, I could probably do it. The head scratcher for me is the query to search for and return all records with the same Runbook Name and then update the date field. I've tried finding something similar I could bastardize in the system but didn't find an example.
Any scripters out there have the time to take a stab at it or is this more complex than I am thinking?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 05:47 PM - edited 01-04-2024 05:49 PM
Seems like something like this, in the script of an After Insert BR would accomplish what you are trying to do.
You would want to test this carefully in a subprod with controlled number of records to make sure things don't get out of hand - hence I added the limit of 100...
(function executeRule(current, previous /*null when async*/ ) {
//We want to find records on cmdb_ci_appl
var apps = new GlideRecord('cmdb_ci_appl');
//where u_dr_runbook = u_dr_runbook_executed
apps.addQuery('u_dr_runbook', current.u_dr_runbook_executed);
apps.setLimit(100); //Comment this out after testing
apps.query();
while (apps.next()) {
//For every app, we set the u_dr_tested to the value of u_test_date)
apps.setValue('u_dr_tested', current.u_test_date);
//Update the record.
apps.update();
}
})(current, previous);
Michael D. Jones
Proud member of the GlideFast Consulting Team!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 05:47 PM - edited 01-04-2024 05:49 PM
Seems like something like this, in the script of an After Insert BR would accomplish what you are trying to do.
You would want to test this carefully in a subprod with controlled number of records to make sure things don't get out of hand - hence I added the limit of 100...
(function executeRule(current, previous /*null when async*/ ) {
//We want to find records on cmdb_ci_appl
var apps = new GlideRecord('cmdb_ci_appl');
//where u_dr_runbook = u_dr_runbook_executed
apps.addQuery('u_dr_runbook', current.u_dr_runbook_executed);
apps.setLimit(100); //Comment this out after testing
apps.query();
while (apps.next()) {
//For every app, we set the u_dr_tested to the value of u_test_date)
apps.setValue('u_dr_tested', current.u_test_date);
//Update the record.
apps.update();
}
})(current, previous);
Michael D. Jones
Proud member of the GlideFast Consulting Team!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 02:51 PM
Hi Michael,
Just played with this today and it is doing exactly what I needed. Thank you for taking the time to put this together, it is very much appreciated. This script will help automate and reduce a lot of effort when logging DR Tests and will help me as an example to learn a bit more about scripting.
Cheers,
Adrian Holloway