无法让 setValue 在 Dynamics CRM 可编辑网格上工作
Can't get setValue to work on a Dynamics CRM editable grid
我希望得到一些关于如何在 Dynamics CRM 365(内部部署)可编辑网格中执行 setValue
的指示:
无论我怎么尝试,我都无法更新网格中的值。此代码获取属性的引用,但 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);
}
}
您应该select传递执行上下文的选项,并使用executionContext.getFormContext()
获取可编辑网格中的当前行。
function updateDocsOK(executionContext) {
var entityObject = executionContext.getFormContext().data.entity;
var att = entityObject.attributes.getByName("new_testtext");
att.setValue("hello");
}
you can’t use Xrm.Page commands on editable grids. In my example I’ll
want to set the probability value.
On the form something like
Xrm.Page.getAttribute(“closeprobability”).setValue(80)
would do the
trick. But this won’t work on editable grids.
Instead I need to use a new method that has been released with
Dynamics 365 (getFormContext).
getFormContext returns a reference for either the form (Xrm.Page) or
the editable grid (GridRow). Meaning we can now have code that will
work in both situations.
getEventSource 可用于 Dynamics CRM 365 可编辑网格获取或设置值:
var year;
var weekNumber;
var selectedRow = null;
var attributeColl = null;
function dateChange(eContext) {
debugger;
var nameAttr = eContext.getEventSource();
var attrParent = nameAttr.getParent();
var startDateField = attrParent.attributes.get("new_startdate");
var date = startDateField.getValue();
//Get week number
var currentWeekNumber = parseFloat(date.getWeek());
//Get full year
const dt = new Date(date);
var currentyear = parseFloat(dt.getFullYear());
//set week value
var new_weeknumbercstField = attrParent.attributes.get("new_weeknumbercst");
new_weeknumbercstField.setValue(currentWeekNumber);
// Set year value
var new_yearcstField = attrParent.attributes.get("new_yearcst");
new_yearcstField.setValue(currentyear);
}
Date.prototype.getWeek = function() {
var onejan = new Date(this.getFullYear(), 0, 1);
return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7);
}
我希望得到一些关于如何在 Dynamics CRM 365(内部部署)可编辑网格中执行 setValue
的指示:
无论我怎么尝试,我都无法更新网格中的值。此代码获取属性的引用,但 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);
}
}
您应该select传递执行上下文的选项,并使用executionContext.getFormContext()
获取可编辑网格中的当前行。
function updateDocsOK(executionContext) {
var entityObject = executionContext.getFormContext().data.entity;
var att = entityObject.attributes.getByName("new_testtext");
att.setValue("hello");
}
you can’t use Xrm.Page commands on editable grids. In my example I’ll want to set the probability value.
On the form something like
Xrm.Page.getAttribute(“closeprobability”).setValue(80)
would do the trick. But this won’t work on editable grids.Instead I need to use a new method that has been released with Dynamics 365 (getFormContext).
getFormContext returns a reference for either the form (Xrm.Page) or the editable grid (GridRow). Meaning we can now have code that will work in both situations.
getEventSource 可用于 Dynamics CRM 365 可编辑网格获取或设置值:
var year;
var weekNumber;
var selectedRow = null;
var attributeColl = null;
function dateChange(eContext) {
debugger;
var nameAttr = eContext.getEventSource();
var attrParent = nameAttr.getParent();
var startDateField = attrParent.attributes.get("new_startdate");
var date = startDateField.getValue();
//Get week number
var currentWeekNumber = parseFloat(date.getWeek());
//Get full year
const dt = new Date(date);
var currentyear = parseFloat(dt.getFullYear());
//set week value
var new_weeknumbercstField = attrParent.attributes.get("new_weeknumbercst");
new_weeknumbercstField.setValue(currentWeekNumber);
// Set year value
var new_yearcstField = attrParent.attributes.get("new_yearcst");
new_yearcstField.setValue(currentyear);
}
Date.prototype.getWeek = function() {
var onejan = new Date(this.getFullYear(), 0, 1);
return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7);
}