Turn All Catalog Items in a Catalog Readonly if part of a group

Walter Toney
Tera Expert

I have the follow

 

Catalog - Marketplace
Catalog items = 800+'

Group = Wishlister

What do we want..

When the Users in the group go through the portal to access the catalog Marketplace we want them to be able to see all Catalog items. but we don't want them to submit anything so the two options is to make all the variables read only or hide the Add to Cart and Order Now buttons with a popup message letting them know the only option they have is to add to the Wish List. 

what is the best way to go about this and any help on how will be great 

I tried

Widget update to the Server Script


(function() {
data.readOnlyMode = false;

// Replace with your group sys_id
var targetGroup = 'YOUR_GROUP_SYS_ID';

// Check membership
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('user', gs.getUserID());
grp.addQuery('group', targetGroup);
grp.query();
if (grp.hasNext()) {
data.readOnlyMode = true; // user is in group → lock variables
}
})();

 

but that didn't work

I tried a Client script and a script include that didnt; work either



3 REPLIES 3

Swapna Abburi
Mega Sage
Mega Sage

hi @Walter Toney 

You can try below option.

1. Create a variable set with onsubmit client script with 'return false' if user is member of a group. this will abort submission of catalog item.

2. add this newly created variable set to all the 800+ catalog items.

Rafael Batistot
Kilo Patron

Hi @Walter Toney 

 

is possible hide the Add to Cart and Order Now buttons

 

in this situation Ankur provide with onChange script 

 

but may you try with onload + glideAjax to check the group

 

In your script include, send gs.getUserID() to get the id of user logged 

 

and validate 

 

https://www.servicenow.com/community/developer-forum/hide-disable-quot-add-to-cart-quot-on-portal-ba...

Walter Toney
Tera Expert

Is there a way we can do this with out modifying all 800 Catalog items