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

ServiceNow:在mdDialog中传入小部件选项架构至spUtil的语法咨询

Passing Custom Option Schema to spUtil for Material Design Modal in ServiceNow

Hey there! I’ve worked through similar scenarios with cloned ServiceNow widgets and modal rendering, so let’s get your widget-form-md setup working correctly with your custom hideRelatedLists option.

Correct Syntax for Passing Options to spUtil.modal

When launching a widget in a Material Design modal via spUtil, you need to explicitly pass your custom options as part of the widgetOptions parameter. Here’s a working example you can adapt:

// Replace with your cloned widget-form-md's actual sys_id
const targetWidgetSysId = 'your-widget-form-md-sys-id-here';

// Define your custom options (match the exact variable name from your option schema!)
const widgetConfig = {
    hideRelatedLists: true, // Set to true/false based on your needs
    // Add any other required form widget options here, e.g.:
    table: 'incident',
    sys_id: current?.sys_id // Use current record ID if applicable
};

// Launch the MD modal with the widget and custom options
spUtil.modal({
    widget: targetWidgetSysId,
    widgetOptions: widgetConfig,
    title: 'Custom Form Modal', // Optional: Set your modal title
    size: 'md' // Optional: Choose sm/md/lg for modal size
}).then(modalInstance => {
    // Optional: Handle modal close events
    modalInstance.result.then(() => {
        console.log('Modal closed - add post-processing here if needed');
    });
});

Common Issues That Might Be Breaking Your Implementation

If your previous attempts failed, check these key points:

  • Exact Variable Name Match: Ensure hideRelatedLists in your widgetConfig matches the exact name you defined in your widget’s option schema (ServiceNow is case-sensitive here).
  • Widget Sys ID Accuracy: Double-check you’re using the sys_id of your cloned widget-form-md, not the original OOTB widget-form.
  • Option Access in Target Widget: Make sure your cloned widget’s client script actually uses c.options.hideRelatedLists to read the value. If you haven’t updated the client logic, the option won’t have any effect.
  • Console Debugging: Open your browser’s dev tools and check the console for errors. If spUtil is undefined, confirm you’re running this in a portal context where spUtil is available.

Quick Validation Tip

To confirm your options are being passed correctly, add a console.log(c.options) in the client script of your widget-form-md and open the modal. You should see hideRelatedLists listed in the output with your specified value.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 10:23:58