- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2018 07:21 AM
Hi All,
We are currently utilising the CIUtils2 script include to populate the impacted services related list on our change form. We also have a companies related list on the change form and this is also populated utilising this same script includes.
We have a business rule currently setup to run on insert/update when the 'configuration item' (cmdb_ci) field changes. This is all working as we would expect, however we now have the requirement that the impacted services and companies related lists should be populated based on all the CIs in the affect Cis related list and not just the 'configuration item' field on the change form. Our current business rule is below, but I am not sure how to amend so that it will look at all affected CIs. I've tried to figure this out, but it looks like the CIUtils2 script is expecting a single CI to be passed in, so would changes need to be made to this as well?
Business rule
function onAfter(current, previous) {
//current.update();
action.setRedirectURL(current);
removeAffectedServices();
removeAffectedCompanies();
addAffectedServices();
addAffectedCompanies();
//checkAffectedServices();
function removeAffectedServices()
{
var m2m = new GlideRecord('task_cmdb_ci_service');
m2m.addQuery('task',current.sys_id);
m2m.addQuery('manually_added','false');
m2m.query();
m2m.deleteMultiple();
}
function removeAffectedCompanies()
{
var m2mcomp = new GlideRecord('u_task_companies');
m2mcomp.addQuery('u_task',current.sys_id);
m2mcomp.addQuery('manually_added','false');
m2mcomp.query();
m2mcomp.deleteMultiple();
}
function addAffectedServices()
{
var ciu = new CIUtils2();
//Find all impacted business services
var services = ciu.cisAffectedByTask(current);
//var services = ciu.cisAffectedByTask(current, ["cmdb_ci_service", "cmdb_ci_windows_server"]);
//var services = ciu.cisAffectedByTask(current, ["ALL"]);
var m2m = new GlideRecord('task_cmdb_ci_service');
for (var i = 0; i < services.length; i++) {
m2m.initialize();
m2m.task = current.sys_id;
m2m.cmdb_ci_service = services[i];
m2m.manually_added = 'false';
m2m.insert();
}
}
//Below code to write the companies to list
function addAffectedCompanies() {
var ciu1 = new CIUtils2();
//Find all impacted business services
//var services1 = ciu1.cisAffectedByTask(current);
//var services1 = ciu1.cisAffectedByTask(current, ["cmdb_ci_service", "cmdb_ci_business_app"]);
var services1 = ciu1.cisAffectedByTask(current, ["ALL"]);
var servicesStr = services1.join(); //Convert to string for more efficient query
//Query for CIs
var grr = new GlideRecord('cmdb_ci');
grr.addQuery('sys_id', 'IN', servicesStr);
grr.query();
var compArr = []; //Initialize a company array
while (grr.next()) {
//Add CI companies to an array
compArr.push(grr.getValue('company'));
}
//Dedup the company array
var uniqueCompanies = new ArrayUtil().unique(compArr);
//Add the company relationship records
for (var i = 0; i < uniqueCompanies.length; i++) {
var m2mgr = new GlideRecord('u_task_companies');
m2mgr.initialize();
m2mgr.u_task = current.sys_id;
m2mgr.u_company = uniqueCompanies[i];
m2mgr.manually_added = 'false';
m2mgr.insert();
}
}
/*function checkAffectedServices()
{
var ciu = new CIUtils2();
//Find all impacted business services
var services = ciu.cisAffectedByTask(current);
//var services = ciu.cisAffectedByTask(current, ["cmdb_ci_service", "cmdb_ci_windows_server"]);
//var services = ciu.cisAffectedByTask(current, ["ALL"]);
var m2m = new GlideRecord('cmdb_ci_service');
m2m.addQuery('sys_id','IN',services.toString() );
m2m.query();
while(m2m.next())
{
var service_name= m2m.name;
var owner= m2m.owned_by;
gs.eventQueue("incident.impact.notify",current,owner,service_name);//Triggers the event for generating email Notification.
}
}*/
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2018 03:52 AM
I was looking at the wrong part of the CIUtils2 script includes, after looking at the correct function 'cisAffectedByTask' and re-reading the notes on the SNGuru site I realised that this already incorporated looking at both the cmdb_ci field and the affected CIs.
We had the business rule set to run after insert/update of the cmdb_ci record, this is what was preventing the rule to update when affected CIs were updated.
We have now changed the rule to run when our change moves from draft to review state. At this point in our configuration ITIL users can no longer amended the affected CIs tab so we know it will contain all the CIs.
I've also added similar logic to a UI Action for users to manually execute as they require.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2018 08:03 AM
Hi,
The way I had it implemented was to have a business rules on task_ci table as that is the table generally associated with Affected CI unless you have a custom table to call the same script include to get the services associated for the inserted CI. I then populate the values into Impacted services.
Also, you need to make sure that when you remove you an affected CI you have a business rule that checks for services that are not associated with any CI to be removed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2018 03:52 AM
I was looking at the wrong part of the CIUtils2 script includes, after looking at the correct function 'cisAffectedByTask' and re-reading the notes on the SNGuru site I realised that this already incorporated looking at both the cmdb_ci field and the affected CIs.
We had the business rule set to run after insert/update of the cmdb_ci record, this is what was preventing the rule to update when affected CIs were updated.
We have now changed the rule to run when our change moves from draft to review state. At this point in our configuration ITIL users can no longer amended the affected CIs tab so we know it will contain all the CIs.
I've also added similar logic to a UI Action for users to manually execute as they require.