javascript - 无法让 setValue 在 Dynamics CRM 可编辑网格上工作
问题描述
我希望获得一些关于如何setValue
在 Dynamics CRM 365(本地)可编辑网格中执行的指示:
无论我尝试什么,我都无法更新网格中的值。此代码获取属性的引用,但 setValue 似乎对网格没有影响。
function updateDocsOK(ctlName, grdName, attributeName) {
var selectedRow = null;
var attributeColl = null;
var twoOptionValue = 0;
try {
//This is the Yes/No value in the dropdown
var ctlValue = Xrm.Page.getAttribute(ctlName).getValue();
if (ctlValue) {
twoOptionValue = 1;
}
//get the selected rows - use the getControl method and pass the grid name.
selectedRow = Xrm.Page.getControl(grdName).getGrid().getRows();
//loop through rows and get the attribute collection
selectedRow.forEach(function (row, rowIndex) {
var att = row.getData().getEntity().attributes.getByName(attributeName);
//This setValue does not work on a two-option
if (att) {
console.log(att.getValue());
att.setValue(twoOptionValue);
console.log(att.getValue());
}
//This setValue does not work on a text field
att = row.getData().getEntity().attributes.getByName("new_testtext");
if (att) {
att.setValue("hello");
}
});
} catch (e) {
Xrm.Utility.alertDialog(e.message);
}
}
解决方案
您应该选择传递执行上下文的选项,并用于executionContext.getFormContext()
获取可编辑网格中的当前行。
function updateDocsOK(executionContext) {
var entityObject = executionContext.getFormContext().data.entity;
var att = entityObject.attributes.getByName("new_testtext");
att.setValue("hello");
}
您不能在可编辑网格上使用 Xrm.Page 命令。在我的示例中,我将要设置概率值。
在表格上类似的东西
Xrm.Page.getAttribute(“closeprobability”).setValue(80)
可以解决问题。但这不适用于可编辑的网格。相反,我需要使用已随 Dynamics 365 (getFormContext) 发布的新方法。
getFormContext 返回表单 (Xrm.Page) 或可编辑网格 (GridRow) 的引用。这意味着我们现在可以拥有适用于这两种情况的代码。
推荐阅读
- flutter - 在我运行颤振通道主后,颤振不再工作
- bash - Bash - 检查参数的数量
- azure-resource-manager - Classic 到 ARM 迁移后虚拟机的 DNS 名称
- swift - 完成事件后,Swift Combine 发布者不会在 flatMap 中触发
- java - 不能在 Eclipse 中使用 Eclemma 覆盖工具
- c++ - (为什么)这个带有临时/匿名对象的模板类的实例化是一个令人烦恼的解析吗?
- sql - 输出存储过程的结果
- eslint - 如何禁用“未找到规则'自定义规则'的定义”错误?
- javascript - 如何从 d3.js 实现图形的 html 变量
- c# - Listview 包含具有外键的项目