How to populate Catalog item based on user login?

suresh40
Tera Contributor

Hi All,

 

I have requirement, to populate  catalog item based on user login using back ground script.

 

Example: If Able Turte login to the portal he has only some catalog item has access to visible That item has visible using background script .Please help me on this .

 

Thanks 

Suresh 

13 REPLIES 13

Hi Ankur,

 

I have Written this script its working fine all catalog item are displaying to all users. Please help me on this.

 

(function execute() {
var catalog = new GlideRecord('sc_cat_item');
catalog.addEncodedQuery('type!=bundle^sys_class_name!=sc_cat_item_guide^type!=package^sys_class_name!=sc_cat_item_content^published_refISEMPTY^active=true');
catalog.addQuery('category', vaInputs.categories.getValue());
catalog.query();
var options = [];
while(catalog.next()){
options.push({'value': catalog.getValue('name'), 'label': catalog.getDisplayValue('name')});

}
return options;
})()

@suresh40 

try this

(function execute() {

	var allCriterias = new sn_uc.UserCriteriaLoader.getAllUserCriteria(gs.getUserID());
	var options = [];
	var gr = new GlideRecord("sc_cat_item_user_criteria_mtom");
	gr.addQuery("user_criteria", "IN", allCriterias.toString());
	gr.query();
	while (gr.next()) {
		options.push({'value': gr.sc_cat_item.name, 'label': gr.sc_cat_item.getDisplayValue()});
	}

	return options;
})();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

For user criteria created catalog items its working fine,  But more then 50 catalogs items we did not created user criteria that are not displaying . For that 50 catalogs items everyone has access its should visible to everyone. Please help me on this.

 

Thanks,

Suresh.

@suresh40 

then please update the script accordingly for those extra items

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader