Cannot use Check...Roles function

Cannot use Check...Roles function

  

Hello,

I'm very new to Outsystems so sorry if this has been asked before. I'm trying to show or hide a link based on if the current user is in the Admin role, which I have defined, and added a user to. I can see the action in Logic > Roles > Admin > CheckAdminRole but I cannot use it.

In an expression I see the error "Unknown object 'CheckAdminRole' in expression". I also cannot drag CheckAdminRole to an action in my screen or block. When I try it shows a little "no symbol" (red circle with a line through it). I've watched the Master Class on Security course and it shows me what to do but when I try to do it Outsystems won't let me. Is this a limitation of the free version?

Thanks,

Jim

....

Forgot to mention, I do see the Admin role listed as a check box in the screen properties, so it seems to be working somewhat. I just can't figure out how to call CheckAdminRole.

Hi James,

If you want to hide or show a link based on the role, you can simply put the condition by dragging checkAdminRole() on link's visible property. 

You also find this on Screen level as well. If you want only authorize users to view your page, You can simply mark checkbox selected. 

https://www.outsystems.com/help/ServiceStudio/9.1/index.htm#t=Handling_security%2FUse_Roles.htm


Sachin

Sachin Mahawar wrote:

Hi James,

If you want to hide or show a link based on the role, you can simply put the condition by dragging checkAdminRole() on link's visible property. 

You also find this on Screen level as well. If you want only authorize users to view your page, You can simply mark checkbox selected. 

https://www.outsystems.com/help/ServiceStudio/9.1/index.htm#t=Handling_security%2FUse_Roles.htm


Sachin


Thanks,

My If Condition window looks like this:

Only the GetUserId() function is available. 

My Logic tab looks like this:

So the role seems to exist.

When I try to drag CheckAdminRole to an action I see this:

So the role is defined I just can't use it. Am I missing something obvious?


Also I tried this for an expression, still no luck:


Sorry, one more edit.

I tried to edit the expression on the link Visible property as you suggested, and I got the same error "Unknown function 'CheckAdminRole' in expression".

Hello James.

First thing: Did you create the role? If not, you need first create the role. Go to the Logic layer and add a role (and change it to Admin, like you are trying to use.

If you already create it, you are trying to use it in a different module than that you create the role.
In this case, set the role to be "Public", publish the module, than go to the module where you are trying to use it, go to Manage Dependencies (the plugin icon in the tool bar), select the module where you create it and than select the role).

Now you can use it in the module. :)

Cheers,
Eduardo Jauch

Solution

Sorry,

You put your comment before I finish mine.
I'm seeing you are in a Mobile.

In Mobile, the Check...Role actions work only in Server Actions. 

Solution

You can take a look in this post to see how to work with Roles in Mobile :)

Eduardo Jauch wrote:

Sorry,

You put your comment before I finish mine.
I'm seeing you are in a Mobile.

In Mobile, the Check...Role actions work only in Server Actions. 


That was it. Here's what I did, I wonder if it's the right way. I created a Server Action called AdminCheck where I call the CheckAdminRole function and output the result. Then in the menu block I added a Data Action that executes AdminCheck and sets it's output to the result. Then my If Condition uses the output from the Data Action. Seems a little convoluted, but it works. Thanks!

-Jim

Hi James,

It is easier using JavaScript.

Add a JavaScript whenever you want to check a role, with the following syntax:

Than you can use the Output (IsManager, or any other name), that will be True if the user has the role, and False otherwise.

You can use this on ClientActions :)

Cheers,
Eduardo Jauch

Eduardo Jauch wrote:

Hi James,

It is easier using JavaScript.

Add a JavaScript whenever you want to check a role, with the following syntax:

Than you can use the Output (IsManager, or any other name), that will be True if the user has the role, and False otherwise.

You can use this on ClientActions :)

Cheers,
Eduardo Jauch

Thanks, I'll try it out.