Apply Dynamic Views on pm_project Based on User Group and Portfolio (View Rules)

venkat ajay
Tera Contributor

Hi Community 👋,

I’d like to share a solution for dynamically applying different form views on the pm_project table based on user group membership and portfolio.


🔍 Requirement

There are two user groups:

  1. TMO

  2. Business Owner

On the pm_project table, we have TMO portfolio records.

Expected Behavior

When a user opens a TMO portfolio project record:

  • Users in TMO group should see TMOView

  • Users in Business Owner group should see BusinessOwnerView

  • Other users should see the default view


🛠 Solution Overview

  • Created two custom views:

    • TMOView

    • BusinessOwnersView

  • Configured a View Rule (System UI → View Rules)

  • Used:

    • User group membership

    • Portfolio condition

    • Current record sys_id from URL

The View Rule dynamically returns the appropriate view name using the answer variable.


📌 View Rule Script

var url = gs.action.getGlideURI().getMap();
var sysId = url.get('sys_id');
gs.info("Inside View rule checking sys_id: " + sysId);

var portName = "968e03849785e214b071f1d71153afff"; // TMO Portfolio sys_id

// Access the current pm_project record
var gr = new GlideRecord('pm_project');
gr.get(sysId);

// Do not apply view rules for list views
if (is_list) {
answer = "";
}

// TMO Admin / Default group view
if (gs.getUser().isMemberOf("81b546db931d2e101378f9d56aba1015") &&
gr.primary_portfolio == portName) {

answer = "Default_view";

// TMO group view
} else if (gs.getUser().isMemberOf("f198537d97202290b071f1d71153afe5") &&
gr.primary_portfolio == portName) {

answer = "TMOview";

// Business Owner group view
} else if (gs.getUser().isMemberOf("8bde324533d962501bf2b1945d5c7bbf") &&
gr.primary_portfolio == portName) {

answer = "BusinessOwnersView";

} else {
answer = "";
}

 

📘 Key Points

  • Table: pm_project

  • Feature Used: View Rules

  • Logic Based On:

    • User group membership

    • Project portfolio

  • Prevents impact on list views using is_list


Advantages of This Approach

  • ✔ No client scripts required

  • ✔ Centralized control using View Rules

  • ✔ Secure (server-side execution)

  • ✔ Easy to extend for additional groups or portfolios

  • ✔ Clean separation of views by role


⚠️ Important Notes

  • Always use sys_id for groups and portfolios to avoid issues with name changes

  • Ensure the View Rule order is correct if multiple rules exist

  • Test with users belonging to multiple groups (priority matters)


🏁 Conclusion

Using View Rules is a powerful and clean way to control form behavior based on user roles and record context.
This approach ensures the right users see the right data layout without duplicating forms or scripts.

Hope this helps someone facing a similar SPM requirement.
Happy to hear improvements or alternate designs from the community 😊

Thanks,

Venkat Ajay P

0 REPLIES 0