Server is mapping to a wrong service instance

SiddharthN62887
Tera Contributor

Hi All,

My case is - In my instance server is connected to a service instance like { Service instance -->uses/usedby (Application) --> run on/runs (server) }.

Now, I have created a after insert or update business rule on server table to populate service instance mapped to that server.

Problem is even when server is classified as development or UAT, it is populating a prod service instance. When I have checked ci relationships. I got to know that dev server is mapped to an application and that application is connected to a prod instance only. And it is happening with multiple records.
Could someone please help me to find the cause here and how to resolve it ?

 

Below is the business rule:-

 

(function executeRule(current, previous /*null when async*/) {

    var apps = [];
    var serviceInstances = [];
    var matchingInstances = [];

    // get applications running on server (Runs on)
    var rel1 = new GlideRecord('cmdb_rel_ci');
    rel1.addQuery('child', current.sys_id);
    rel1.addQuery('type.parent_descriptor', 'Runs on');
    rel1.query();
    while (rel1.next()) {
        apps.push(rel1.parent.toString());
    }

    // get service instances using applications
    var rel2 = new GlideRecord('cmdb_rel_ci');
    rel2.addQuery('child', 'IN', apps);
    rel2.addQuery('type.parent_descriptor', 'Uses');
    rel2.query();
    while (rel2.next()) {
        serviceInstances.push(rel2.parent.toString());
    }
    //gs.print(serviceInstances);

    var si = new GlideRecord('cmdb_ci_service_auto');
    si.addEncodedQuery('sys_idIN'+ serviceInstances);
    si.query();
    while(si.next()){
        if(current.classification == si.used_for){
            //gs.print('classification ' +server.classification);
            //gs.print('used for ' +si.used_for);
            matchingInstances.push(si.sys_id.toString());
            //gs.print("in the service instance block");
        }
    }
    //gs.print(matchingInstances);

    if(matchingInstances.length > 0){
        current.u_applications = matchingInstances.join(',');
        current.setWorkflow(false);
        current.update();
        //gs.print("updated server record");
    }


})(current, previous);
3 REPLIES 3

MURALIR20469232
Tera Guru

Hello @SiddharthN62887 ,

 

Kindly check the classification value and used for value. I don't think that UAT value will be there in used for field. 
Check the value and compare with classification and used for field. 

 

*************************************************************************************************************
If my post is useful, please indicate its helpfulness by selecting " Helpful." This action benefits both the community and me.

If you like to share any information, please comment in this post so that it will be useful for our community. 

Regards
Murali.K.V.R

Hi  MURALIR20469232

Business rule is working fine, the problem is with ci relationships

 

Tanushree Maiti
Tera Patron

Hi @SiddharthN62887 

 

1)  Ensure in your instance you have created separate Application Services for each environment (e.g., AppName - DEV, AppName - UAT, AppName - PROD) Or  AppName - PROD ,AppName - non- PRODz

Also Ensure the Dev server is only related to the Dev application service. 

Refer: How to model the CMDB (following the CSDM) when you need to take business criticality and environmen... 

 

2)

Add an environment check (like environment field) to your script logic.

The rule must first check the environment of the server triggering the event, and then query for the corresponding Service Instance (DEV service for DEV servers or non-prod servers, PROD service for PROD servers) rather than defaulting to the first related record it finds.

 

3) If the Discovery pattern or payload looks at non-production servers, the Identification and Reconciliation Engine (IRE) might  incorrectly identify the CIs.

Verify the Identification Rules .

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti