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);
2 REPLIES 2

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