Employee Center - Restrict Access to see Mega Menu Items linked to Catalog Items using User Criteria

kmolson73
Tera Expert

We have our catalog items setup with User Criteria for who is allowed to view and submit those items. We are setting up Employee Center Mega Menu using Advanced Portal Navigation and have setup the Menu Items. How do I add a condition to the menu item to look at the user criteria for that specific catalog item? I am able to adjust the condition if I just do javascript: gs.getUser().isMemberOf('sys_id of group') and that does work but some of our catalog items use user criteria that includes roles/groups and individual users. Currently the users can see all of the menu items, if they click on one that they don't have access to that catalog item it will tell them in the next screen but we'd prefer they don't even see those menu items in the list. 

3 REPLIES 3

MANOJM820830658
Tera Contributor

Hi @kmolson73 , did you find a way to hide them, if yes can you please help me too?

We are working on a solution now, I will update this post as soon as we have it working. Basically, it involves creating a script include to look up the user criteria and then calling that script include in the menu item conditions passing the needed information to the script include and returning true or false. 

First we created a script include like below:

Name: getUserCriteria

Application: Global

Accessible from: All Application scopes

Script:

var getUserCriteria = Class.create();

getUserCriteria.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    demo: function(catItemSysid,sysIdUser) {

 

        var catItemSysid = JSUtil.nil(catItemSysid) ? this.getParameter('sysparm_sys_id') : catItemSysid;

        var sysIdUser = JSUtil.nil(sysIdUser) ? this.getParameter('sysparm_sys_id') : sysIdUser;

    //gs.log('Cat Item is: '+catItemSysid);

        var lookupUserCriteria = new GlideRecord('sc_cat_item_user_criteria_mtom');

        lookupUserCriteria.addQuery('sc_cat_item', catItemSysid);

        lookupUserCriteria.query();

 

var arrayUtil = new global.ArrayUtil();

var criteriaArray = new Array();

 

//Get the sys ID of the user criteria's for the catalog item and put into an Array

while(lookupUserCriteria.next()){

criteriaArray.push(lookupUserCriteria.user_criteria.toString());

}

 

Then in our Advanced Portal Navigation/Menu Items (that point to a catalog item that has user criteria) we added the following to the condition:

javascript:var foo=new global.getUserCriteria(); foo.demo('4a869872e1f335009b4a3e25ee98475d', gs.getUserID()); //use the sys id of the catalog item

You only need to add this condition to the menu items that are linked to a catalog item with user criteria