我正在 Power Platform 中构建模型驱动应用程序。我的表格已全部设置完毕。默认情况下,在表单加载时,lm_drafttoggle 列设置为“Yes”,其在 Dataverse 中的基础值为“1”。
因此,我需要的是默认隐藏这三个字段(lm_drafttoggle、lm_technicalapprover 和 lm_cabapprover)。如果用户将 lm_drafttoggle 更改为“否”,则这三个字段应该可见。
我尝试了以下方法,但它对表单加载没有任何作用...
function onFormLoad(executionContext) {
var formContext = executionContext.getFormContext();
// Get value of the 'lm_drafttoggle' field
var toggleValue = formContext.getAttribute("lm_drafttoggle").getValue();
if (toggleValue === "No") {
// Hide the three fields
formContext.getControl("lm_peerreviewer").setVisible(false);
formContext.getControl("lm_technicalapprover").setVisible(false);
formContext.getControl("lm_cabapprover").setVisible(false);
} else if (toggleValue === "Yes") {
// Show the three fields
formContext.getControl("lm_peerreviewer").setVisible(true);
formContext.getControl("lm_technicalapprover").setVisible(true);
formContext.getControl("lm_cabapprover").setVisible(true);
}
}
function onSave(executionContext) {
onFormLoad(executionContext);
}
提前非常感谢。 LM
function onFormLoad(executionContext) {
var formContext = executionContext.getFormContext();
// Get value of the 'lm_drafttoggle' field
var toggleValue = formContext.getAttribute("lm_drafttoggle").getValue();
if (toggleValue === "No") {
// Hide the three fields
formContext.getControl("lm_peerreviewer").setVisible(false);
formContext.getControl("lm_technicalapprover").setVisible(false);
formContext.getControl("lm_cabapprover").setVisible(false);
} else if (toggleValue === "Yes") {
// Show the three fields
formContext.getControl("lm_peerreviewer").setVisible(true);
formContext.getControl("lm_technicalapprover").setVisible(true);
formContext.getControl("lm_cabapprover").setVisible(true);
}
}
function onSave(executionContext) {
onFormLoad(executionContext);
}
如果您想在更改“lm_drafttoggle”字段时格式化表单,则必须使用类似于以下内容的代码:
function formatForm(executionContext) {
var formContext = executionContext.getFormContext();
// Get value of the 'lm_drafttoggle' field
var toggleValue = formContext.getAttribute("lm_drafttoggle").getValue();
if (!toggleValue) {
// Hide the three fields
formContext.getControl("lm_peerreviewer").setVisible(false);
formContext.getControl("lm_technicalapprover").setVisible(false);
formContext.getControl("lm_cabapprover").setVisible(false);
} else {
// Show the three fields
formContext.getControl("lm_peerreviewer").setVisible(true);
formContext.getControl("lm_technicalapprover").setVisible(true);
formContext.getControl("lm_cabapprover").setVisible(true);
}
}
function onFormLoad(executionContext) {
formatForm(executionContext);
var formContext = executionContext.getFormContext();
formContext.getAttribute("lm_drafttoggle").addOnChange(formatForm);
}
我假设该字段是一个复选框(2 个值),并且 getValue 方法将返回一个布尔值而不是字符串值,因此我将该更改合并到代码中。