How Do I Reference Qualify Business Service based on Business Application

WazzaJC
Tera Expert

Hi Team,

I would really appreciate any help/guidance on how to achieve/modify the script I have, to achieve this.

On my Incident form I have a field for Service (business_service) and Business Application (u_business_application).

 

I want to put a Reference Qualifier on the Service (business_service) field, so that when Business Application is populated, the only options that show in the Service field are children of the parent Business Application.

 

I currently have the following script include and reference qualifier, which can be used to achieve the same, for showing CI's that relate to a service offering, but how can I amend this script include and the related reference qualifier javascript, so that I can achieve a similar process for only showing Service related to the Business Application.

 

Here is the Reference Qualifier Javascript I need to modify:

javascript: new IncidentUtils().getCis(current.service_offering);

And Here is associated script include I am wanting to modify:

var IncidentUtils = Class.create();
IncidentUtils.prototype = {

    getCis: function(so) {
        var getCiArr = [];
        if (so) {
            var cm = new GlideRecord('cmdb_ci');
            cm.addEncodedQuery('sys_class_name=service_offering');
            cm.addQuery('sys_id', so);
            cm.query();
            if (cm.next()) {
                var gr = new GlideRecord('cmdb_rel_ci');
                gr.addQuery('parent', cm.sys_id);
                gr.query();
                while (gr.next()) {
                    getCiArr.push(gr.child.sys_id.toString());
                }
                return "sys_idIN" + getCiArr.join(',');
            }
        }
    },

    type: 'IncidentUtils'
};

 Thanks very much - any help/guidance, very much appreciated.

1 ACCEPTED SOLUTION

SANDEEP28
Mega Sage

@WazzaJC 

 

Reference qualifier for Service field dictionary: Replace "u_business_application" field with your business application field name if its different

javascript: new IncidentUtils().getServiceList(current.u_business_application);

 

Add below code in "IncidentUtils" script include 

getServiceList: function(business_application) {
        var getServices = [];

        if (business_application) {

            var grCIRelationsip = new GlideRecord('cmdb_rel_ci');
            grCIRelationsip.addQuery('parent.sys_class_name=cmdb_ci_business_app');
            grCIRelationsip.addQuery('parent', business_application);
            grCIRelationsip.query();

            while (grCIRelationsip.next()) {
                getServices.push(grCIRelationsip.getValue('child'));
            }
            return "sys_idIN" + getServices.join(',');
        }
    },

I tested this script include in PDI & its working 

 

SANDEEP28_0-1690142314987.png

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !! This will help others as well 🙂

 

View solution in original post

7 REPLIES 7

SANDEEP28
Mega Sage

@WazzaJC Could you please share table name of Service & business application ? How are they related to each other ?

Hi Sandeep,

yes of course - thank you for coming back to me.

 

'Services' is the standard OOTB Services table as per PDI (cmdb_ci_service)

 

'Business Applications' is the standard OOTB Business Applications table as per PDI (cmdb_ci_business_app)

 

They are related as Parent and Child in the standard OOTB 'CI Relationships' Table (cmdb_ci_rel)

 

Thanks again for any help/guidance.

AnveshKumar M
Tera Sage
Tera Sage

Hi @WazzaJC ,

Try this.

 

Reference qualifier: 

javascript: new IncidentUtils().getServiceCIs(current.u_business_application);

 

And, add another method called "getServiceCIs" to your Script Include like the one below,

 

getServerCIs: function(ba) {

        var getCiArr = [];

        if (ba) {

            var cm = new GlideRecord('cmdb_rel_ci');

            cm.addQuery('parent.sys_class_name=cmdb_ci_service');

            cm.addQuery('child', ba);

            cm.query();

            while (cm.next()) {

getCiArr.push(gr.parent.sys_id.toString());

}

                return "sys_idIN" + getCiArr.join(',');

            }

        },

 

Thanks,
Anvesh

Hi Anvesh - many thanks for trying to help, much appreciated.

Can you try this on your own PDI and confirm is this script set up works for you?

I feel it is getting close as looks to almost be working but it is still not working for me?

If you could try on your side and confirm this definitely works on your PDI - many thanks Anvesh.