URL (link) Field to display on the HTML, only to specify Role

Elton2
Tera Contributor

Hi everyone, good morning!

The URL is successfully rendering(image attachment), but it only needs to appear for a specific Role 

(available to Managers if there is a link) 

When the manager clicks on the link(url) will be directed to the specific folder

 

 
/*SERVER SCRIPT*/
var grDisplayURL = new GlideRecord('table_with_url_field');
    grDisplayURL.addEncodedQuery('manager_roleDYNAMIC52635e963f510100a9ad2572f2b4874c^url_folderISNOTEMPTY');
    grDisplayURL.query();
   
    if(grDisplayURL.next()){
    data.display_url_folder = grDisplayURL.getDisplayValue('url_folder');
}
 
<!--HTML-->
<td class="link">
    <a href="{{options.link}}" target="{{options.target}}" data-toggle="tooltip" class="link-url-folder">          
      <span class="display-url-folder">{{data.display_url_folder}}</span>
    </a>
</td>
 

however, I've already created the query, (I don't know if it's right), but it's rendering several URLs on the page (img query example attachment).

 

Could anybody help me?! Please

Tks

 
2 ACCEPTED SOLUTIONS

RaghavSh
Kilo Patron

Try adding gs.hasRole() as below:

  if(grDisplayURL.next()){
if(gs.hasRole('itil'))  // add your role name here instaed of itil
{
    data.display_url_folder = grDisplayURL.getDisplayValue('url_folder');
}
else{
data.display_url_folder='';
}
}

Raghav
MVP 2023

View solution in original post

Mohith Devatte
Tera Sage
Tera Sage

Hello @Elton2 ,

you can add a condition in server and HTML script to display it for few roles 

 

server script :

/*SERVER SCRIPT*/
var grDisplayURL = new GlideRecord('table_with_url_field');
    grDisplayURL.addEncodedQuery('manager_roleDYNAMIC52635e963f510100a9ad2572f2b4874c^url_folderISNOTEMPTY');
    grDisplayURL.query();
   
    if(grDisplayURL.next()){
data.showURL=false;
if(gs.hasRole('your_role_name'))
{
data.showURL=true;
}
else
{
data.showURL=false;
}
    data.display_url_folder = grDisplayURL.getDisplayValue('url_folder');
}

 

HTML:

<td class="link" >
    <a href="{{options.link}}" target="{{options.target}}" data-toggle="tooltip" class="link-url-folder">   
<div ng-if="data,showURL==true">       
      <span class="display-url-folder">{{data.display_url_folder}}</span>
</div>
    </a>

 

Hope this helps 

mark my answer correct if this helps you 

Thanks

 

 

View solution in original post

4 REPLIES 4

RaghavSh
Kilo Patron

Try adding gs.hasRole() as below:

  if(grDisplayURL.next()){
if(gs.hasRole('itil'))  // add your role name here instaed of itil
{
    data.display_url_folder = grDisplayURL.getDisplayValue('url_folder');
}
else{
data.display_url_folder='';
}
}

Raghav
MVP 2023

Elton2
Tera Contributor

Hi RaghavSh, good afternoon!

Its working,

Thanks so much!!!

Mohith Devatte
Tera Sage
Tera Sage

Hello @Elton2 ,

you can add a condition in server and HTML script to display it for few roles 

 

server script :

/*SERVER SCRIPT*/
var grDisplayURL = new GlideRecord('table_with_url_field');
    grDisplayURL.addEncodedQuery('manager_roleDYNAMIC52635e963f510100a9ad2572f2b4874c^url_folderISNOTEMPTY');
    grDisplayURL.query();
   
    if(grDisplayURL.next()){
data.showURL=false;
if(gs.hasRole('your_role_name'))
{
data.showURL=true;
}
else
{
data.showURL=false;
}
    data.display_url_folder = grDisplayURL.getDisplayValue('url_folder');
}

 

HTML:

<td class="link" >
    <a href="{{options.link}}" target="{{options.target}}" data-toggle="tooltip" class="link-url-folder">   
<div ng-if="data,showURL==true">       
      <span class="display-url-folder">{{data.display_url_folder}}</span>
</div>
    </a>

 

Hope this helps 

mark my answer correct if this helps you 

Thanks

 

 

Hi Mohith, good afternoon!!!

Its working too! 

Thanks so much!!!