Set Catalog Item User Reference Variable based upon cmdb_rel_ci

purdue
Kilo Sage

Hello,

Any assistance is appreciated.

 

I have a cat item which has the following

1. Reference Variable pointing to cmdb_ci_business_app table.   2. Once I make a selection  from 1 then a lookup selectbox filters values from cmdb_rel_ci see below.

Screenshot 2024-11-13 at 2.05.42 PM.png

3. There is a reference variable to the user table which they would populate with the child.owned_by when 2 is selected.  I tried below but it is not working.

Screenshot 2024-11-13 at 2.14.46 PM.png

1 ACCEPTED SOLUTION

Here is the corrected Script Include, with some temporary log lines, so if you are still not getting the expected results you can share which system logs you are seeing (filter on Message starts with SI)

var Cloud_Owned_by = Class.create();
Cloud_Owned_by.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    updateOwned: function () {
        var results = 'none';        
        var buildingid = this.getParameter('sysparm_application_service');
        gs.info('SI running: buildingid = ' + buildingid);
        var loc = new GlideRecord('cmdb_ci');
        loc.addQuery('sys_id', buildingid);  
        loc.query();
        if (loc.next()) {  
            gs.info('SI record found: ' + loc.name);
            results = {
                "owned_by": loc.getValue('owned_by'),
                "managed_by": loc.getValue('managed_by')
            };
            gs.info('SI results: ' + JSON.stringify(results));
            return JSON.stringify(results);
        } else {
            return results;
        }
    },
    type: 'Cloud_Owned_by'
});

View solution in original post

7 REPLIES 7

Here is the corrected Script Include, with some temporary log lines, so if you are still not getting the expected results you can share which system logs you are seeing (filter on Message starts with SI)

var Cloud_Owned_by = Class.create();
Cloud_Owned_by.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    updateOwned: function () {
        var results = 'none';        
        var buildingid = this.getParameter('sysparm_application_service');
        gs.info('SI running: buildingid = ' + buildingid);
        var loc = new GlideRecord('cmdb_ci');
        loc.addQuery('sys_id', buildingid);  
        loc.query();
        if (loc.next()) {  
            gs.info('SI record found: ' + loc.name);
            results = {
                "owned_by": loc.getValue('owned_by'),
                "managed_by": loc.getValue('managed_by')
            };
            gs.info('SI results: ' + JSON.stringify(results));
            return JSON.stringify(results);
        } else {
            return results;
        }
    },
    type: 'Cloud_Owned_by'
});

Community Alums
Not applicable

javascript: 'fieldname of the app in the parent table=' + current.variables.select_your_application_service_environment.owned_by + '^active=true^internal_integration_user=false'; 

purdue
Kilo Sage

Thanks Brad for the assistance.   I appreciate it.

Chad