How to hide a submenu in a Portal based on a user condition

Elena7
Tera Expert

Hello,

 

I need to  hide a submenu in a Portal for users who doesn't meet some conditions.

I wrote a condition in my Menu item, but it doesn't work: "gs.getUser().getRecord().u_retail_staff == true || gs.getUser().getRecord().u_target_si == 100"

 

Elena7_0-1685028119890.png

 

Does anybody can help me?

 

Best regards,

Elena

1 ACCEPTED SOLUTION

Mallidi Suma
Tera Guru

Hi @Elena7 ,

 

As per my understanding getRecord() will only work for the sys_user table existing fields, since you are trying it with custom fields it is not getting executed. So You can create one Script Include and call the Script Include in the condition. Please find the below example.

 

Step 1:- Create a custom field called Vendor and Request menu Item Should only be visible to the users who are having this vendor check box as true.

 

Step 2:- Created a script Include.

 

Code:-


ReturnVendorValue: function()
{
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',gs.getUserID());
gr.query();
if(gr.next())
{
return gr.u_vendor;
}
},
 
Screenshot:-
Screenshot 2023-05-26 at 1.07.12 AM.png

 

Step 4:- Add a Menu Item Condition

 

Screenshot 2023-05-26 at 1.07.50 AM.png
 

Code:-

new GetVendorValue().ReturnVendorValue()

 

Please mark my answer as helpful and accept it as a solution, if it helps

View solution in original post

2 REPLIES 2

Mallidi Suma
Tera Guru

Hi @Elena7 ,

 

As per my understanding getRecord() will only work for the sys_user table existing fields, since you are trying it with custom fields it is not getting executed. So You can create one Script Include and call the Script Include in the condition. Please find the below example.

 

Step 1:- Create a custom field called Vendor and Request menu Item Should only be visible to the users who are having this vendor check box as true.

 

Step 2:- Created a script Include.

 

Code:-


ReturnVendorValue: function()
{
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',gs.getUserID());
gr.query();
if(gr.next())
{
return gr.u_vendor;
}
},
 
Screenshot:-
Screenshot 2023-05-26 at 1.07.12 AM.png

 

Step 4:- Add a Menu Item Condition

 

Screenshot 2023-05-26 at 1.07.50 AM.png
 

Code:-

new GetVendorValue().ReturnVendorValue()

 

Please mark my answer as helpful and accept it as a solution, if it helps

Elena7
Tera Expert

Hello @Mallidi Suma ,

It works perfectly, thank you very much!

Best regards,

Elena