Different fields visibility based on user department

rah dev
Tera Contributor

Hi Community, good day, I am stuck in a requirement where I need to control field visibility on the “My Requests” page in Service Portal based on user department. If a user belongs to the HR department, they should see additional fields in the request list, but if the user belongs to the IT department, they should only see limited fields like request number and short description. I want to know the best practice to achieve this, whether it should be handled via widget customization, ACLs, or any other recommended approach. Any guidance or example would be really helpful.

 
Thanks in Advance
rahdev_0-1776119478211.png

 

4 REPLIES 4

lauri457
Tera Sage

Why does the hr department need to see additional fields on this page? What is the actual business requirement? Are they agents? Instead of trying to modify a page that serves a certain purpose, consider what would be the intended place to view whatever it is they are trying to see. 

Tanushree Maiti
Kilo Patron

Hi @rah dev 

 

You can achieve this by following steps:

1. Create a Display Business Rule on RITM to get the user's department and pass it to the client side.

  • Name: Get Department for Portal
  • Table: Requested Item
  • When: display
  • (function executeRule(current, previous /*null when async*/) {
        var user = gs.getUser();
        g_scratchpad.userDept = user.getDepartmentID(); })(current, previous);

    2. Create a script to hide/show variables based on g_scratchpad.userDept

    • Name: Show/Hide RITM Variables based on Department
    • Table: Catalog Item 
    • Type: onLoad
    • UI Type: All
    • Applies to: RITM (Ensure checkbox is checked)
    • function onLoad() {    var hrDeptSysId = 'YOUR_HR_DEPARTMENT_SYS_ID_HERE';
      
          // Variables to hide for non-HR
          var hrVariables = ['hr_variable_1', 'hr_variable_2'];
      
          if (g_scratchpad.userDept != hrDeptSysId) {
              // User is NOT in HR (e.g., IT), hide extra variables
              for (var i = 0; i < hrVariables.length; i++) {
                  g_form.setDisplay(hrVariables[i], false);
              }
          } else {
              // User is in HR, ensure variables are shown
              for (var j = 0; j < hrVariables.length; j++) {
                  g_form.setDisplay(hrVariables[j], true);
              }
          }
      }
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

@Tanushree Maiti 

It would be nice if you could share screenshots for your approach which shows how to show/hide the fields in My Requests page in portal

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron

@rah dev 

this will require heavy customization

You will have to clone the OOTB widget, then make changes to it based on your department logic, then add this new widget on the page again

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader