Populate the Unused catalog items into a variable

VAMSI AMMISETTY
Tera Contributor

Hi Everyone,

 

I created a script include to the pull data of "Catalog Items without Recent RITM's requested from past six months" on to a variable.  But script is not working can someone help me on this please.

 

 

var CatalogItemsWithoutRecentRITM = Class.create();
CatalogItemsWithoutRecentRITM.prototype = {
    initialize: function() {},

    getItemsWithoutRecentRITM: function() {
        var sixMonthsAgo = new GlideDateTime();
        sixMonthsAgo.addMonths(-6);
        
        var grCatalogItem = new GlideRecord('sc_cat_item');
        grCatalogItem.query();
        
        var itemsWithoutRITM = [];
        
        while (grCatalogItem.next()) {
            var grRITM = new GlideRecord('sc_req_item');
            grRITM.addQuery('cat_item', grCatalogItem.sys_id);
            grRITM.addQuery('sys_created_on', '>=', sixMonthsAgo);
            grRITM.query();
            
            if (!grRITM.hasNext()) {
                itemsWithoutRITM.push(grCatalogItem.sys_id.toString());
            }
        }
        
        return itemsWithoutRITM;
    },

    type: 'CatalogItemsWithoutRecentRITM'
};

 

 

 

Reference Qualifier:

 

javascript: new CatalogItemsWithoutRecentRITM().getItemsWithoutRecentRITM();

 


Thanks

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

When used in a reference qualifier, the format needs to be 'sys_idIN' then the comma-separated list of sys_ids, so you either need to change the reference qualifier to include this before the script call, or just change the script return

 

return 'sys_idIN' + itemsWithoutRITM.join(',');

This will filter the list of available records on a reference variable.  Do you actually want to populate this list of sys_ids into the value or Selected box of a list collector variable?

 

View solution in original post

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

When used in a reference qualifier, the format needs to be 'sys_idIN' then the comma-separated list of sys_ids, so you either need to change the reference qualifier to include this before the script call, or just change the script return

 

return 'sys_idIN' + itemsWithoutRITM.join(',');

This will filter the list of available records on a reference variable.  Do you actually want to populate this list of sys_ids into the value or Selected box of a list collector variable?

 

Thanks for the Response @Brad Bowman  

Gangadhar Ravi
Giga Sage
Giga Sage

@VAMSI AMMISETTY  

 

I tested this in PDI and looks like it is working fine. Can you please check if you have any ACL or query BR on the table that is causing issues.

Thanks for the Response @Gangadhar Ravi