App Services mapped to a CI - SNC.BusinessServiceManager()?

Kelly Logan
Kilo Sage

I'm looking to build an easy way to determine the application services a CI is mapped to so I can use one of the group fields on it for notifications. I found a script include ApplicationServiceGraphDataAPIs that has a promising method,

getApplicationServicesAssociatedWithC(ciList, useSvcCiAssoc), which essentially calls
SNC.BusinessServiceManager.
getServicesAssociatedWithCi(ciList, useSvcCiAssoc)
 
I have been able to call it without errors with code like this (see below) that try to find an Application Service I created manually, with a CI that is a manual endpoint (that is updated as directed and shows up in the svc_ci_assoc list).

 

var ci = new GlideRecord('cmdb_ci');
ci.get("a30667e29744f91066673f11f053af0d");

// ADZCFLS01 sys_id a30697e29744f91066673f11f053af0d
var app = new ApplicationServiceGraphDataAPIs();
var useSvcCiAssoc = true;
var ciList = [ci]; // starting with CI name

var svcList = app.getApplicationServicesAssociatedWithCi(ciList,useSvcCiAssoc);

var svc = new GlideRecord('cmdb_ci');
gs.print(svcList);
for (var i in svcList){
  gs.print(i);
}

 

but while the returned object seems to be a GlideRecord object, but it doesn't seem to have values: .name, .getDisplayValue() and .getClassDisplayValue() all return undefined.
 
My fallback option is to query the svc_ci_assoc table for the ci in the ci_id reference field and then pull the cmdb_ci_service field value. That seems messy though. That table has more than the endpoints in it and the service listing is generic, I might need to add something to filter for Application Services.
 
I haven't been able to find any useful documentation on SNC.BusinessServiceManager to confirm what the parameters should be and what the returned value is. The only mention I've seen so far is someone else asking a question about a different method and they weren't pointed at any docs either. Anyone have any ideas?
 
Note: I have looked through articles on Application services like  Application Services: How to use them? and  Application Services: Tips and Tricks that have some useful info on setting up App services, but haven't seen anyone talking about how to find a mapped service from a CI the way the system does.
 
1 REPLY 1

Mathew Hillyard
Mega Sage

Hi Kelly,

This API is private but is partly documented: https://docs.servicenow.com/en-US/bundle/vancouver-api-reference/page/app-store/dev_portal/API_refer...

 

The function you are looking at is not included so I would advise against using this API as you won’t know if/when ServiceNow changes the specification, meaning your code would break.

 

The Service Configuration Item Association (SCIA) table is absolutely the right place to find your data. The Service Id field should only contain a record within the Automated Business Service table hierarchy - basically all Application Service types. The good news is that it is automatically populated for most classes (only the Mapped Application Service table requires some manual logic). The bad news is that in populating this table, lots of Manual Endpoint records get created (one per CI). However you can easily filter what you need. Do bear in mind that every target CI needs to be connected to an App Service, but how many levels in the CMDB hierarchy depends on settings inside each Application Service. All types of Application service use SNC.BusinessServiceManager().populateApplicationService() - this function takes the number of levels. The maximum that can be chosen is 8 and for Mapped Application Services I believe there is a hard limit of 1,000 records per manual calculation. Dynamic CI Groups use a CMDB Group so effectively have one “level”, which means that they are always up to date in the SCIA table.

Therefore, I would advise investigating how Application Services are being populated and at how many levels in the instance you are working with. Just because you fail to find a CI in the table, doesn’t necessarily mean it’s not linked to the Application Service.


On a side note, I’m not sure whether the API has defects as I’ve noticed anomalous behaviour - one of the other parameters of the populateApplicationService() function is a list of blacklisted CI relationship types. My testing on both customer instances and a PDI is that these exclusions are sometimes ignored and the excluded types result in records being created in the SCIA table. However, as the code is hidden, I cannot identify the root cause.

It also depends on how mature the CMDB is - if Service Mapping is not in use and best practices have not been followed, then there may be unexpected CIs in the SCIA table.

 

If your customer is using impacted service calculation and the SCIA table, it might be prudent to add some logic to prevent inserts for classes/types that you don’t want to include in impacted service calculation.

 

I hope this helps!

Mat