Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Visibility for Menu Item on Portal

babarat1
Tera Contributor

Hi All, I have a custom Menu item name "Test".

My requirement as follows:

1. I need to make it visible only for users who are part of a specific table

2. Example : there are multiple tables in Snow but I have a custom table "u_xyz". A logic should be applied that the instance analyzes the "logged in" user if he is part of the "u_xyz" table and if yes the "test" Menu item should be visible. Else it should not be visible.

babarat1_0-1677570911475.png

 

 

Need help to achieve the same. 

Thanks,

@Ankur Bawiskar @Community Alums @Allen Andreas @SatyakiBose @newhand 

1 ACCEPTED SOLUTION

@babarat1  you can just try this

 

var loggedIn = gs.getUserID();
var grgetUser = new GlideRecord('u_authorized_approver');
grgetUser.addQuery('u_user',loggedIn);
//grgetUser.addQuery('u_user.active','true');
grgetUser.query();
if(grgetUser.next())
return true;

else

return false;

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

View solution in original post

9 REPLIES 9

SatyakiBose
Mega Sage

Hello @babarat1 

One way to achieve this:

  • Set the menu item type = page
  • Under the condition you can call a script include like this:
    new ScriptIncludeName().function();
  • In the script include, you can write the function as: (this script is just for reference. you can modify it as per your business requirement)

 

 

 

 getMenuItem: function() {
        var gr = new GlideRecord('asmt_assessment_instance');
        gr.addQuery('user', gs.getUserID());
        gr.addEncodedQuery('stateINready,wip');
        gr.addEncodedQuery('metric_type.evaluation_methodINattestation_v2,risk_assessment,vdr_risk_asmt');
        gr.query();

        var re = new GlideRecord('sn_risk_advanced_event');
        re.addQuery('opened_by', gs.getUserID());
        re.addEncodedQuery('stateNOT IN4,3');
        re.query();
  
        return (gr.next() || pe.next()) && gs.isLoggedIn();
    }​

 

 

You can change the table name and query conditions as per the tables in your instance.

Also keep in mind, that if the menu item is supposed to show a list of record, then you have a portal page defined where this list would be available.

How do I return the value from here sir?

I have the script and it returns the sysid of the user

var loggedIn = gs.getUserID();
var grgetUser = new GlideRecord('u_authorized_approver');
grgetUser.addQuery('u_user',loggedIn);
//grgetUser.addQuery('u_user.active','true');
grgetUser.query();
if(grgetUser.next()){
gs.print(loggedIn);
gs.print("user "+grgetUser.u_user);
}

 

i do not know what to return from here

 

TIA

 

@babarat1 you can just return true or false.

 

if record exists return true. if not return false.

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

@babarat1  you can just try this

 

var loggedIn = gs.getUserID();
var grgetUser = new GlideRecord('u_authorized_approver');
grgetUser.addQuery('u_user',loggedIn);
//grgetUser.addQuery('u_user.active','true');
grgetUser.query();
if(grgetUser.next())
return true;

else

return false;

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

It depends on what data are you trying to match.

This line of code, doesn't seem quite right.

grgetUser.addQuery('u_user',loggedIn);

Is the u_user field a reference field to the sys_user table?

Basically you will have to find a field in both the tables - your custom table, and sys_user table that you can map to for validation of the user.