Using gs.getProperty in Script Include not working

matthew_hughes
Kilo Sage

I'm using the following script include function to reference a system property with a variable instead of manually entering the value of the System Property:

 

 invalidCBPTier: function() {
 
        var arrayUtil = new ArrayUtil();
        var app = [];
        var holding = [];
var criticalRelationshipType = gs.getProperty('apm.criticallyused.relationship');
gs.log('This should return the value of the criticalRelationshipType ' + criticalRelationshipType);
 
        var dbv = new GlideRecord('u_business_app_with_critical_cbp');
dbv.addEncodedQuery('barelps_type='+criticalRelationshipType+'^ba_install_status!=70^ba_u_cbp_tierINTier A,Tier B,Tier C');
        dbv.addOrderBy('ba_name');
        dbv.query();
        while (dbv.next()) {
            var appName = dbv.ba_sys_id;
 
            if (!arrayUtil.contains(holding, appName)) {
                app.push(dbv.ba_sys_id.toString());
                holding.push(appName.toString());
            }
        }
 
        var invalidCBPs = [];
 
        var busApp = new GlideRecord('cmdb_ci_business_app');
        busApp.addQuery('sys_id', 'IN', app);
        busApp.query();
        while (busApp.next()) {
            var cbpTier = busApp.getValue('u_cbp_tier');
            var cbps = [];
 
            var cbpGr = new GlideRecord('u_business_app_with_critical_cbp');
            cbpGr.addQuery('ba_sys_id', busApp.sys_id);
            cbpGr.query();
            while (cbpGr.next()) {
                //gs.print('BP Name : '+ cbpGr.bp_name); // added to check the current BP
                //gs.print('BP SubCat : '+ cbpGr.bp_u_subcategory); // // added to check the current SubCat Tier
                cbps.push(cbpGr.getValue('bp_u_subcategory').toString());
            }
            //gs.print('Array: '+ cbps); // Check array after final record has been pushed
 
            if (cbpTier == 'Tier A' && !arrayUtil.contains(cbps, 'Tier A')) {
                invalidCBPs.push(busApp.sys_id.toString());
                //gs.print('Invalid does not contain A');
            } else if (cbpTier == 'Tier B' && arrayUtil.contains(cbps, 'Tier A')) {
                invalidCBPs.push(busApp.sys_id.toString());
                //gs.print('Tier B: Invalid contains A');
            } else if (cbpTier == 'Tier B' && !arrayUtil.contains(cbps, 'Tier B')) {
                //gs.print('Tier B: Invalid does not contains B');
                invalidCBPs.push(busApp.sys_id.toString());
            } else if (cbpTier == 'Tier C' && arrayUtil.contains(cbps, 'Tier A')) {
                invalidCBPs.push(busApp.sys_id.toString());
                //gs.print('Tier C: Invalid contains A');
            } else if (cbpTier == 'Tier C' && arrayUtil.contains(cbps, 'Tier B')) {
                //gs.print('Tier C: Invalid contains B');
                invalidCBPs.push(busApp.sys_id.toString());
            } else {
                //do nothing;
            }
        }
        return invalidCBPs; // Return the values to the report: Apps critically linked but with wrong CBP Tier
    },
 
The System Property I'm using in my script is is:
matthew_hughes_0-1693466212534.png

 

 

However, what I've found is that if I replace the old code dbv.addEncodedQuery('barelps_type=3a174f47db5dbf0073609ab9db961964^ba_install_status!=70^ba_u_cbp_tierINTier A,Tier B,Tier C'); with   dbv.addEncodedQuery('barelps_type='+criticalRelationshipType+'^ba_install_status!=70^ba_u_cbp_tierINTier A,Tier B,Tier C');

 

It causes some reports to not display any results. I was just wondering if someone knows where I'm going wrong.

2 REPLIES 2

Sagar Pagar
Tera Patron

Hi @matthew_hughes,

 

I believe there is no issue with gs.getProperty() method. Might be you are working with scope application. hence gs.log() will not work.

 

Try by replacing gs.log() with gs.info(); and check.

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

Hi @Sagar Pagar 

 

It doesn't explain though why the results in the report will show when using 3a174f47db5dbf0073609ab9db961964, but not criticalRelationshipType

 

Do I need to declare something right at the very start of my script include?