Jelly Script to check roles

maryc
Tera Contributor

Hi ,

I am trying to check the roles of the logged in user to display a piece of HTML .

<j2:if test="$[gs.hasRole('R1') || gs.hasRole('R2') || gs.hasRole('R3')]">

                                                 

                              <a data-toggle="collapse" href="#dropdown-lvl3">

                                    Sample Menu Item

                              </a>

</j2:if>

This code is not working.. .Any idea what is the correct way to do this?

Thanks in advance

1 ACCEPTED SOLUTION

Inactive_Us1474
Giga Guru

Hi Mary,



You have used gs.hasRole in Jelly Tag, it should be used in <g:evaluate> tags. You can refer below :



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<g2:evaluate>


  var checkRole=gs.hasRole('chat_admin')||gs.hasRole('chat'); // return true if success


</g2:evaluate>


<j2:if test="$[checkRole]">


  <p>Your message</p> // a piece of HTML.


</j2:if>


</j:jelly>



Thanks.


Akhil



Hit Like/Helpful/Correct, if applicable.


View solution in original post

3 REPLIES 3

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Inactive_Us1474
Giga Guru

Hi Mary,



You have used gs.hasRole in Jelly Tag, it should be used in <g:evaluate> tags. You can refer below :



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<g2:evaluate>


  var checkRole=gs.hasRole('chat_admin')||gs.hasRole('chat'); // return true if success


</g2:evaluate>


<j2:if test="$[checkRole]">


  <p>Your message</p> // a piece of HTML.


</j2:if>


</j:jelly>



Thanks.


Akhil



Hit Like/Helpful/Correct, if applicable.


Hi Akhil,



I tried this but it is not working.



I have a Dropdown with Cost Model Names. It's option should depend on the logged in Person. If User have 'cost_admin' role, he should have access to view all Cost Model in Dropdown. Else user should be able to view Choices of Cost Models only whose 'Visible' field Checkbox is true. Cost Model is a table so different Filter conditions for Different users. How to implement it?