How can we hide cart icon on header in service portals depending on company in ServiceNow

Ankita Gupte
Kilo Sage

We have cart icon on header menu of Service Portal, this can be hide if we set below value to false but I want it to hide only when logged in user is from company A. for logged in user from other company except A it should be visible.

 

{
"enable_cart": {
"displayValue": "true",
"value": false
},
"enable_wishlist": {
"displayValue": "true",
"value": false
}
}

Please advice how can we achieve this

10 REPLIES 10

Did you try with UI policy? Please sahre screen shot of portal where you want to hide.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

It on a header menu on service portal.

AnkitaGupte_0-1706015265936.png

 

Shaqeel
Mega Sage

hi @Ankita Gupte  🙂

 

To hide the cart icon on the header menu of Service Portal for users of a specific company, you can use a combination of scripting and CSS. Here are the steps:

 

1. Identify the user's company:

You can use the GlideUser API to get the user's company. For example, g_user.getCompanyID() will return the sys_id of the company that the current user belongs to.

 

2. Create a UI Script:

Create a UI Script that checks if the current user belongs to company A. If they do, add a CSS class to the body tag. Here's a sample script:

 

javascript

if(g_user.getCompanyID() == 'sys_id_of_company_A'){ document.body.classList.add('hide-cart-icon');

}

 

3. Add CSS to hide the cart icon:

In the Service Portal's theme or in a CSS Include, add the following CSS:

css

.hide-cart-icon .navbar .shopping-cart { display: none;

}

 

4. Apply the UI Script:

Apply the UI Script to the Service Portal. You can do this by adding the UI Script to the Header or Footer HTML field of the Service Portal's Theme record.

 

Please note that you need to replace 'sys_id_of_company_A' with the actual sys_id of the company. Also, the CSS selector might need to be adjusted based on your Service Portal's layout and theme.

 

Regards

Shaqeel


***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.

***********************************************************************************************************************





Regards

Shaqeel

Hi Shaqeel, I am new to this module and we have not yet created any UI Scripts in our instance so I am not aware what will be the impact of the same. Is there any other way we can implement this?

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Ankita Gupte 

 

What is the impact if we keep cart like this for all users?

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************