The CreatorCon Call for Content is officially open! Get started here.

I want to manage the visibility of catalog items only to the subscribers to the Service Offerings

pdurgapavan
Tera Contributor

I would like to show the catalog items to the users who subscribed to the Service Offerings. Let's say On the service_offering table, there is a service offering called "SAP Retail " and Abel was added to the Subscribed by user related list and there is a catalog item called "SAP Access for new hires " added under "Items orderable by subscribers" related list then users whoever subscribed can able to see the catalog item rest of all the users cannot able to see the catalog item.

 

pdurgapavan_0-1757947894276.png

pdurgapavan_1-1757947911303.png

Could anyone please guide me to achieve this.

 

@Dr Atul G- LNG 

@Ankur Bawiskar 

 

1 ACCEPTED SOLUTION

@pdurgapavan 

Logic I shared should work fine, provided you are using correct table and fields to query and grab the value

var catItemSysId = '6117697c1b803a1096064152b24bcba2'; // give sysId of your catalog item

var offeringArr = [];

var gr = new GlideRecord("service_subscribe_sys_user");
gr.addQuery("sys_user", user_id);
gr.query();
while (gr.next()) {
    offeringArr.push(gr.getValue('service_offering'));
}

gs.info('Offering arr is' + offeringArr.toString());

var rec = new GlideRecord('sc_cat_item_subscribe_mtom');
rec.addQuery('sc_cat_item', catItemSysId);
rec.addQuery('service_offering', 'IN', offeringArr.toString());
rec.query();
if (rec.hasNext()) {
    answer = true;
} else {
    answer = false;
}

Try running this in background script and pass user sysId

var catItemSysId = '6117697c1b803a1096064152b24bcba2'; // give sysId of your catalog item

var offeringArr = [];

var gr = new GlideRecord("service_subscribe_sys_user");
gr.addQuery("sys_user", 'hardCodeSysId');
gr.query();
while (gr.next()) {
    offeringArr.push(gr.getValue('service_offering'));
}

gs.info('Offering arr is' + offeringArr.toString());

var rec = new GlideRecord('sc_cat_item_subscribe_mtom');
rec.addQuery('sc_cat_item', catItemSysId);
rec.addQuery('service_offering', 'IN', offeringArr.toString());
rec.query();
gs.info('row count' + rec.getRowCount() + ' encoded query is' + rec.getEncodedQuery());

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

View solution in original post

7 REPLIES 7

@pdurgapavan 

Logic I shared should work fine, provided you are using correct table and fields to query and grab the value

var catItemSysId = '6117697c1b803a1096064152b24bcba2'; // give sysId of your catalog item

var offeringArr = [];

var gr = new GlideRecord("service_subscribe_sys_user");
gr.addQuery("sys_user", user_id);
gr.query();
while (gr.next()) {
    offeringArr.push(gr.getValue('service_offering'));
}

gs.info('Offering arr is' + offeringArr.toString());

var rec = new GlideRecord('sc_cat_item_subscribe_mtom');
rec.addQuery('sc_cat_item', catItemSysId);
rec.addQuery('service_offering', 'IN', offeringArr.toString());
rec.query();
if (rec.hasNext()) {
    answer = true;
} else {
    answer = false;
}

Try running this in background script and pass user sysId

var catItemSysId = '6117697c1b803a1096064152b24bcba2'; // give sysId of your catalog item

var offeringArr = [];

var gr = new GlideRecord("service_subscribe_sys_user");
gr.addQuery("sys_user", 'hardCodeSysId');
gr.query();
while (gr.next()) {
    offeringArr.push(gr.getValue('service_offering'));
}

gs.info('Offering arr is' + offeringArr.toString());

var rec = new GlideRecord('sc_cat_item_subscribe_mtom');
rec.addQuery('sc_cat_item', catItemSysId);
rec.addQuery('service_offering', 'IN', offeringArr.toString());
rec.query();
gs.info('row count' + rec.getRowCount() + ' encoded query is' + rec.getEncodedQuery());

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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @pdurgapavan 

The visibility of a catalog item can be handled through user criteria. Please create the appropriate user criteria and then check if it works as expected.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

dzmitryKon
Tera Contributor

1. Have you checked 

Its a mature/service oriented way to manage catalogue; however may require some limitation in terms of 1-many ; many-to-many relationship; (if not mistaken it was impossible to link 1 Item to multiple offerings (check :)))

Alternatively you can build some Scripted User criteria to check dynamically link between users - related offerings - Related items and you may need to add some custom m2m tables in between

Thanks;
Please mark Solved/Helpful if Solved/was Helpful 🙂