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

Business Central动态可见属性使用:对象监控行字段动态显隐需求

动态控制Object Monitoring Line字段显隐的解决方案

核心思路

通过判断当前Object Monitoring Line所属Component Address的层级(父/子级),在页面层面动态控制"Type"和"Number"字段的显示状态。

具体实现步骤

1. 确保表关联与层级标识

首先确认Object Monitoring Line表中存在指向所属Component Address的关联字段(如Component Address ID),同时在Component Address表中添加可区分父/子级的标识:

  • 新增布尔字段Is Child Address,标记Component Address 2为true,Component Address 1为false;
  • 或者利用现有字段规则判断,比如父级地址编码固定为ADDR1,子级为ADDR2。

2. 页面层动态控制字段可见性

方法一:字段属性表达式直接控制

在Object Monitoring Line页面的"Type"和"Number"字段属性中,设置Visible的表达式:

Visible = Rec.Component Address.Is Child Address;

如果用编码规则判断,可替换为:

Visible = Rec.Component Address.Code = 'ADDR2';
方法二:页面触发器动态设置

在页面的OnAfterGetRecord触发器中添加逻辑,根据当前记录所属地址层级切换字段可见性:

trigger OnAfterGetRecord();
begin
    if Rec.Component Address.Is Child Address then begin
        CurrPage.TypeControl.Visible(true);
        CurrPage.NumberControl.Visible(true);
    end else begin
        CurrPage.TypeControl.Visible(false);
        CurrPage.NumberControl.Visible(false);
    end;
end;

(注:TypeControl和NumberControl需替换为页面上对应字段的实际控件名称)

3. 验证多场景适配

测试以下两种场景确保逻辑生效:

  • 直接打开Component Address 1的Object Monitoring Lines,确认"Type"和"Number"字段隐藏;
  • 打开Component Address 2的Object Monitoring Lines,确认自身记录显示字段、父级记录隐藏字段。

注意事项

  • 层级标识要稳定,避免因编码调整导致判断失效;
  • 若存在多级地址结构,可扩展逻辑为Rec.Component Address.Parent ID = ''识别顶级父级,或通过层级深度字段判断。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 22:18:11