catalog item

Ak_12
Tera Contributor

Hi, 

In catalog item, there is a reference field reference to alm_asset table, and requested by field reference to user table. so the requested field autopopulate with username who logged in. so if i select the asset it should list the asset which belongs to user company. Here both user table and asset table both as company field.Screenshot (11).pngScreenshot (12).png

5 REPLIES 5

PrashantLearnIT
Giga Sage

Hi @Ak_12 

 

Make Asset field dependant on requested for field under variable configuration.

 

 

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

Community Alums
Not applicable

Hi @Ak_12 ,

 

Can you try to set a reference qualifier on the Select Asset to Disposal field, to only get data of the assests of the requestors org.

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks & Regards,

Sanjay Kumar

@Community Alums 
Hi, this is my script, its not working. 
var getCompayDetails = Class.create();
getCompayDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDisposalCompany: function(requestedBy){

       var assetSysIds = [];
       if (requestedBy) {
           var userGr = new GlideRecord('sys_user');
           if (userGr.get(requestedBy)) {
               var userCompany = userGr.company;
               if (userCompany) {
                   var assetGr = new GlideRecord('alm_asset');
                   assetGr.addQuery('company', userCompany);
                   assetGr.query();
                   while (assetGr.next()) {
                       assetSysIds.push(assetGr.getUniqueValue());
                   }
               }
           }
       }
       return assetSysIds.join(',');
   },
    type: 'getCompayDetails'
});

Community Alums
Not applicable

Hi @Ak_12 ,

 

The issue that i can see in your script- You are accessing userGr.company directly, which doesn't get the value of the field. You should use the getValue() method to fetch the value of a field.

Ensure that the script include name getCompayDetails does not contain a typo and is client callable.
Further you need to check if the reference qualifier / filter in your client script is correctly set after fetching the data.

Updated Script-

var getCompanyDetails = Class.create();
getCompanyDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getDisposalCompany: function(requestedBy) {
        var assetSysIds = [];
        if (requestedBy) {
            var userGr = new GlideRecord('sys_user');
            if (userGr.get(requestedBy)) {
                var userCompany = userGr.getValue('company');
                if (userCompany) {
                    var assetGr = new GlideRecord('alm_asset');
                    assetGr.addQuery('company', userCompany);
                    assetGr.query();
                    while (assetGr.next()) {
                        assetSysIds.push(assetGr.getUniqueValue());
                    }
                }
            }
        }
        return assetSysIds.join(',');
    },
    type: 'getCompanyDetails'
});

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks & Regards,

Sanjay Kumar