Scripted breakdown mapping with multiple return values

Dale Cameron
Giga Contributor

Can you have a script for a breakdown mapping return multiple SYS_IDs?

I have a use case where we want to breakdown incident indicators by the affected services (calculated by the associated CI).

This data is already being collected in a custom table, but the issue is that each incident can be related to/affect multiple services.

I tried return an array of sys_ids in a breakdown mapping script, but that didn't work.

Any Ideas?

1 ACCEPTED SOLUTION

Probably you need to use this hack:



Re: How to get the sys_id of the current record in an Indicator Script?



Besides I would change the script, like so:



function getImpactedServices(sys_id){


        var businesServices = [];


        var impactedservices = GlideRecord('task_cmdb_ci_service');


        impactedservices.addQuery('task', sys_id);


        impactedservices.addQuery('cmdb_ci_service.sys_class_name','cmdb_ci_service');


        impactedservices.query();


        while(impactedservices.next()){


                  businesServices.push(impactedservices.cmdb_ci_service);


        }


return businesServices;


}


getImpactedServices(current.sys_id);


View solution in original post

6 REPLIES 6

peterh_smith
Tera Contributor

It sounds like you want to match patterns of CIs.   Take a look at the CI Query Builder.   It will help with this.   It is not integrated with list filters or reports yet, but it will accelerate experiments to see what works best.



I like to structure things like this as related lists, where possible.   I posted an example for a simpler scenario a while ago.   It uses a comma separated list of sys_ids in a separate query to stitch together the related records.



Not able to get the Report of all Incidents along with the Group table details even by using DB VIE...


Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

Returning an array of sys_id's should work.


Are you sure they match the elements in the breakdown source?


Thanks arnoud , I did have a script logic error so that it was returning the wrong SYS_IDs, but after I fixed that it still didn't create any breakdown information.


Let me give you all more detail now that I know it's possible to return an array of SYS_IDs.


  • I've created a breakdown source for Business Service where the fact table is cmdb_ci_service and the field is sys_id
  • Then I created an automated breakdown using that sources that has a scripted breakdown mapping (Shown Below)
  • I then run the [PA Incident] Historic Data Collection Job, but when I look and the open incident scorecard there are no result in the business service breakdown... there services are there, no incidents are associated.


The Breakdown mapping script:


The script uses the Impacted Service table which I thought was custom, but turns out is built in.


the task field has the incident sys_id and the cmdb_ci_service has the business servcie sys_id



function getImpactedServices(c){


        var businesServices = [];


        var impactedservices = GlideRecord('task_cmdb_ci_service');


        impactedservices.addQuery('task', c.sys_id);


        impactedservices.addQuery('cmdb_ci_service.sys_class_name','cmdb_ci_service');


        impactedservices.query();


        while(impactedservices.next()){


                  businesServices.push(impactedservices.cmdb_ci_service);


        }


return businesServices;


}


getImpactedServices(current);



I can run the in the background script editor with a given incident id and get valid results.


  1. I can for sure return an array of SYS_IDs right?
  2. current.sys_id is the incident sys_id right? I think this is where I may be failing... I'm assuming current is the current incident.



Any Thoughts?


Probably you need to use this hack:



Re: How to get the sys_id of the current record in an Indicator Script?



Besides I would change the script, like so:



function getImpactedServices(sys_id){


        var businesServices = [];


        var impactedservices = GlideRecord('task_cmdb_ci_service');


        impactedservices.addQuery('task', sys_id);


        impactedservices.addQuery('cmdb_ci_service.sys_class_name','cmdb_ci_service');


        impactedservices.query();


        while(impactedservices.next()){


                  businesServices.push(impactedservices.cmdb_ci_service);


        }


return businesServices;


}


getImpactedServices(current.sys_id);