Dynamics 365 FO表单:选Lookup后动态显示关联额外展示字段
解决方案:Dynamics 365 F&O表单动态展示关联数据(无需保存)
针对你在表单中选择RoleCode后动态展示关联头衔的需求,以下是几个可行的修正方案:
方案一:非绑定控件+下拉框Modified方法(修正版)
你之前的问题出在数据源字段的modified方法作用域无法访问表单控件,只需将逻辑移到表单控件的modified方法中即可:
- 在表单设计器添加一个非绑定StringEdit控件,命名为
StakeholderNameDisplayControl,设置属性:AllowEdit = No(只读)、DataSource = 无。 - 找到表单上的
RoleCode下拉控件,右键添加modified方法,编写逻辑:
public void modified() { TUStakeholderRoles holderRoles; str title = 'NA'; super(); // 获取当前选中的RoleCode值并查询关联头衔 if (this.value()) { select firstOnly title from holderRoles where holderRoles.reportToPosition == this.value(); } // 更新非绑定控件文本 StakeholderNameDisplayControl.text(title); }
方案二:表单数据源的Display方法(推荐)
如果偏好使用Display方法,需在表单数据源而非表上创建,这样表单设计器能识别并支持动态刷新:
- 打开表单的数据源(假设为
TUStakeholderRoles_ds),右键添加Display Method,命名为StakeholderNameDisplay:
public display str StakeholderNameDisplay() { TUStakeholderRoles holderRoles; TUStakeholderRoles currentRec = TUStakeholderRoles_ds.cursor(); if (currentRec.RoleCode) { select firstOnly title from holderRoles where holderRoles.reportToPosition == currentRec.RoleCode; return holderRoles.title ? holderRoles.title : 'NA'; } return 'NA'; }
- 回到表单设计器,展开数据源节点即可看到该Display方法,直接拖到表单中作为控件。
- 在
RoleCode控件的modified方法中添加刷新逻辑:
public boolean modified() { boolean ret; ret = super(); // 仅刷新当前记录,触发Display方法更新 TUStakeholderRoles_ds.refreshRecord(); return ret; }
关键注意事项
- 避免依赖表级Display方法的动态更新,表级方法存在缓存机制,无法实时响应表单字段变化。
- 所有控件的modified方法必须调用
super(),确保系统默认逻辑正常执行。 - 非绑定控件需设置为只读,防止用户误编辑。
内容的提问来源于stack exchange,提问作者user4833581
相关产品推荐
相关产品推荐

