How to populate Catalog item based on user login?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 03:07 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 05:33 AM
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;
})()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 07:34 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 08:21 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 08:36 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader