How to use roles in Mobile app for hiding and showing the content

Hi All,

I created Roles in Mobile App. Added users in to role as well but unable to write the condition as I write in Reactive Web App. Can anyone tell me how to use roles for hiding and visible content purpose.


thanks

João Delgado wrote:

Shailendra,


Look into this post: 

https://www.outsystems.com/forums/discussion/41118/how-to-set-roles-in-mobile-application/ 


They explain a solution through Javascript.

  https://success.outsystems.com/Documentation/10/Reference/OutSystems_APIs/JavaScript_API/Security


Best regards,


João Delgado

 I don't understand where to write the condition?  When i try to write "checkIfCurrentUserHasRole" it shows me error

 

Hello Shailendra,

Can you show us what you are trying to do? A print could be useful.


Kind regards,

Rui Barradas

Solution

Hi Shailendra,

For the Javascript approach using the checkIfCurrentUserHasRole() function, you would have to use a Javascript node in order for that function to get recognized. 

I have attached a small sample OML to demonstrate how you could hide visible elements (I have used a Button) using the Javascript function.

Hope you find it useful.

Regards,

Nordin


Solution

Hello Shailendra,


You shall create a client action under Logic tab, create an output parameter also(eg: HasRole of boolean type) and inside action flow take a Jscript widget and can write the script there.

Eg : $parameters.<JS_Output_Parameter_OfTypeBoolean> = $public.Security.checkIfCurrentUserHasRole($roles.<YourRoleName>);

this output parameter can now be assigned to output parameter of your client action(HasRole).

This will work. Let us know if you still face issue.


Regards,

Sanjay


Nordin Ahdi wrote:

Hi Shailendra,

For the Javascript approach using the checkIfCurrentUserHasRole() function, you would have to use a Javascript node in order for that function to get recognized. 

I have attached a small sample OML to demonstrate how you could hide visible elements (I have used a Button) using the Javascript function.

Hope you find it useful.

Regards,

Nordin


Thanks Nordin Ahdi. It is working fine now. It is very simple to use it in Mobile App. :-)


 

Shailendra Phadke wrote:

Nordin Ahdi wrote:

Hi Shailendra,

For the Javascript approach using the checkIfCurrentUserHasRole() function, you would have to use a Javascript node in order for that function to get recognized. 

I have attached a small sample OML to demonstrate how you could hide visible elements (I have used a Button) using the Javascript function.

Hope you find it useful.

Regards,

Nordin


Thanks Nordin Ahdi. It is working fine now. It is very simple to use it in Mobile App. :-)


 

 And your .oml file works fine on Mozilla but not mine. I always run with chrome. Why this happen?

 

Hi Shailendra,

It is indeed :). I'm glad I was able to help.

Do you mind marking my post as solution, because you marked your own post as solution now.

Thanks,

Nordin

Shailendra Phadke wrote:

And your .oml file works fine on Mozilla but not mine. I always run with chrome. Why this happen?

I work with Chrome too, and it is working as expected on my side. 

Remember that after you grant or revoke the Manager role to your user, you will have to logout and log back in to the application for it to have effect.

Regards,

Nordin

Nordin Ahdi wrote:

Hi Shailendra,

It is indeed :). I'm glad I was able to help.

Do you mind marking my post as solution, because you marked your own post as solution now.

Thanks,

Nordin

 

 Yes, I repair it. 

"Remember that after you grant or revoke the Manager role to your user, you will have to logout and log back in to the application for it to have effect. " : Yes.


Good job! 

Enjoy developing with OutSystems :)