Skip to main content
Solved

how to hide a card based on the requester group the logged user belongs to.

  • February 13, 2023
  • 6 replies
  • 856 views

I want to hide a card based on the requester group that a user logged in to portal. Currently I can control to show the card only when they are logged in using the code below.

 

{{#if portal.logged_in}}

<card> test </card>

{{/if}}

 

but how can I get the requester group of the logged in user?

 

 

Best answer by Rutger Bockholts

Hi ,

 

I don't have the object Requester Group available for filtering in a script, however there are other options that might fit you:

 

USER_INFO.*

where * can be one from the list below.

  • address
  • departments
  • email
  • first_name
  • full_name
  • is_agent
  • is_dept_head
  • job_title
  • last_name
  • location_name
  • mobile
  • profile+pic
  • reporting_manager
  • time_format
  • time_zone
  • user_id

 

A requester can be member of multiple department at the same time. In below script, I check if someone is member of the department “PortalCards”. If true, two additional cards will be shown.

 

The script has to be placed in the Footer section under the existing code.

<script>
  var UserIsMember = JSON.stringify(USER_INFO.departments).includes('PortalCards');
      console.log('is member: ' + UserIsMember);
  if(UserIsMember === true) {
  CARDS = CARDS.concat([
    {
      url: '/support/catalog/items/16',
      img: 'https://assets10.freshservice.com/assets/cdn-ignored/sprites/service-catalog/employee-offboarding-new-bc4e0be4f7b73db5bea9231e98bec0c53c7ec42b538830b5c36e213d908a3b9e.png',
      title: 'Leaver',
      content: '',
    },
 {
         url: '/support/employee_onboarding/new',
      img: 'https://assets1.freshservice.com/assets/cdn-ignored/sprites/service-catalog/newhire-new-2aa3dc9b94fce8c1a2f6ac47bf0922ebb0e23dfb5a2a20edf502d7feb29cad90.png',
      title: 'New Starter',
      content: '',
    }
  ]);
      }
</script>

 

Hope this helps you further.

 

regards,

 

Rutger Bockholts

Freshworks

View original
Did this topic help you find an answer to your question?

6 replies

Rutger Bockholts
Community Debut
Forum|alt.badge.img+4

Hi ,

 

I don't have the object Requester Group available for filtering in a script, however there are other options that might fit you:

 

USER_INFO.*

where * can be one from the list below.

  • address
  • departments
  • email
  • first_name
  • full_name
  • is_agent
  • is_dept_head
  • job_title
  • last_name
  • location_name
  • mobile
  • profile+pic
  • reporting_manager
  • time_format
  • time_zone
  • user_id

 

A requester can be member of multiple department at the same time. In below script, I check if someone is member of the department “PortalCards”. If true, two additional cards will be shown.

 

The script has to be placed in the Footer section under the existing code.

<script>
  var UserIsMember = JSON.stringify(USER_INFO.departments).includes('PortalCards');
      console.log('is member: ' + UserIsMember);
  if(UserIsMember === true) {
  CARDS = CARDS.concat([
    {
      url: '/support/catalog/items/16',
      img: 'https://assets10.freshservice.com/assets/cdn-ignored/sprites/service-catalog/employee-offboarding-new-bc4e0be4f7b73db5bea9231e98bec0c53c7ec42b538830b5c36e213d908a3b9e.png',
      title: 'Leaver',
      content: '',
    },
 {
         url: '/support/employee_onboarding/new',
      img: 'https://assets1.freshservice.com/assets/cdn-ignored/sprites/service-catalog/newhire-new-2aa3dc9b94fce8c1a2f6ac47bf0922ebb0e23dfb5a2a20edf502d7feb29cad90.png',
      title: 'New Starter',
      content: '',
    }
  ]);
      }
</script>

 

Hope this helps you further.

 

regards,

 

Rutger Bockholts

Freshworks


dschacter
Community Debut
  • Community Debut
  • 1 reply
  • April 20, 2023

Hello, 

I am trying to do the same thing, however I’m not very good at coding so I have some questions if you don’t mind. I’ve color coded them. I appreciate any help. Thank you!

RED – is an underscore the correct way to enter a space in the department name?

YELLOW – I don’t know where to find the image asset URL, do I need one?

GREEN – how do I know what the title is?

BLUE – I know what the offboarding URL is because it’s a service category, but for onboarding I used the pre-built onboarding functionality in FS. Will it be the same URL?

MAGENTA – again, I’m not sure how to check if the title is correct.

 

<script>

  var UserIsMember = JSON.stringify(USER_INFO.Department).includes(Human_Resources_and_Talent_Management_Team);

      console.log('is member: ' + UserIsMember);

  if(UserIsMember === true) {

  CARDS = CARDS.concat([

    {

      url: '/support/catalog/items/15',

      img: 'https://assets10.freshservice.com/assets/cdn-ignored/sprites/service-catalog/employee-offboarding-new-bc4e0be4f7b73db5bea9231e98bec0c53c7ec42b538830b5c36e213d908a3b9e.png',

      title: 'Leaver',

      content: '',

    },

 {

         url: '/support/employee_onboarding/new',

      img: 'https://assets1.freshservice.com/assets/cdn-ignored/sprites/service-catalog/newhire-new-2aa3dc9b94fce8c1a2f6ac47bf0922ebb0e23dfb5a2a20edf502d7feb29cad90.png',

      title: 'New Starter',

      content: '',

    }

  ]);

      }

</script>

 


Forum|alt.badge.img+5
  • Skilled Expert
  • 30 replies
  • May 24, 2023

@Rutger Bockholts  Does this still work in the portal v2? I’m trying to use your code and it’s not doing anything.


Rutger Bockholts
Community Debut
Forum|alt.badge.img+4

@tyler.brandt . I just tried the script from my post in the Footer section (Save+Publish), created the department “PortalCards” and added myself here, and the two cards are showing up on the portal home page (v2) after a refresh.

 

Make sure the 2 cards are not added via the no-code designer in first place, the script should generate the content or each card from the script if you're member of the earlier mentioned department.

 

Kind regards,

Rutger Bockholts

Freshworks


Forum|alt.badge.img+5
  • Skilled Expert
  • 30 replies
  • May 25, 2023
Rutger Bockholts wrote:

@tyler.brandt . I just tried the script from my post in the Footer section (Save+Publish), created the department “PortalCards” and added myself here, and the two cards are showing up on the portal home page (v2) after a refresh.

 

Make sure the 2 cards are not added via the no-code designer in first place, the script should generate the content or each card from the script if you're member of the earlier mentioned department.

 

Kind regards,

Rutger Bockholts

Freshworks

 

Thank you for responding! I tried again and my mistake was putting the code in the bottom of my home page code, not the “footer” code. It’s working great now. Thank you!


Forum|alt.badge.img+4
  • Skilled Expert
  • 9 replies
  • January 18, 2024

This is an interesting solution but very limited on the available properties. For instance, custom attributed of requesters are not available or even the VIP flag.


The issue with using department to house this extra information is that with an AD integration to sync users, like we use, the additional department is removed on the next sync.


Reply