You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ServiceNow:如何限制Business Service可见性并实现组与服务多对多关联

Solution for Managing Group-Business Service M2M Relationships & Filtering in ServiceNow

Hey there, let's break down how to fix your two key issues—setting up proper many-to-many (M2M) relationships between groups and business services, then filtering those services correctly for users in the self-service portal and incident forms. I've worked through similar ServiceNow configurations before, so here's a practical step-by-step approach:

1. Setting Up a Proper Many-to-Many Relationship Between Groups & Business Services

The core problem with your current setup is the one-to-one limitation of the "Users supported" field. Here's how to fix that with a dedicated M2M relationship:

  • Create a Many-to-Many Relationship Table

    • Navigate to System Definition > Relationships in your ServiceNow instance.
    • Click "New" to create a new relationship:
      • Name it something clear, like "Groups Supporting Business Service"
      • Set the Parent table to Business Service [cmdb_ci_service]
      • Set the Related table to Group [sys_user_group]
      • Check the Many-to-many checkbox to enable M2M functionality
    • Save the relationship. This will automatically create a junction table (usually named something like u_groups_services—note this table name for later use).
  • Add Related Lists to Forms

    • For the Group form: Add a related list pointing to your new M2M table, filtered to show all business services the group supports.
    • For the Business Service form: Add a related list pointing to the same M2M table, filtered to show all groups that support the service.
      Now you can associate multiple groups with a single business service, and vice versa—exactly what your requirement needs.

2. Filtering Business Services for Users in Portals & Incident Forms

With the M2M relationship in place, you'll need to update the reference qualifier on the "Business Service" field to pull only services supported by the user's groups. Here's how:

For Incident Forms & Service Catalog Record Producers

  • Open the field configuration for the "Business Service" field (either on the incident table or your record producer).
  • Switch to the Advanced tab for the reference qualifier, then use this script (replace u_groups_services with your actual M2M table name):
    var userGroups = gs.getUser().getMyGroups().toArray();
    var serviceQuery = new GlideRecord('u_groups_services');
    serviceQuery.addQuery('group', 'IN', userGroups);
    serviceQuery.query();
    var serviceIds = [];
    while (serviceQuery.next()) {
        serviceIds.push(serviceQuery.service.toString());
    }
    'sys_idIN' + serviceIds.join(',');
    
  • Save the configuration. This script grabs all groups the current user belongs to, then fetches every business service linked to those groups via the M2M table, filtering the field to only show those services.

For Self-Service Portal Pages

  • Ensure the portal's widget or form displaying the "Business Service" field uses the same reference qualifier logic. If you're using a standard Service Portal widget, you can update the field's qualifier directly in the widget's configuration, or add the script above to the widget's server-side script to filter the options before they're rendered.

Quick Testing Tip

  • Log in with a user who belongs to multiple groups, each linked to different business services, to verify that only the services supported by their groups appear in the dropdown.

内容的提问来源于stack exchange,提问作者Pavlo Rudenko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:58:33