通常需要直接打开某一个form,并且有时需要在打开时直接设置默认值。
SDK中直接给提供了下面这个方法: Xrm.Utility.openEntityForm
结合我个人的实际例子再进行说明:
OpenOrder = function () {
var parameters = {};
// 为查找类型字段赋值
parameters["new_servicerequset"] = Xrm.Page.data.entity.getId();
parameters["new_servicerequsetname"] = Xrm.Page.getAttribute("new_requestname").getValue();
// 为文本类型字段进行赋值
parameters["new_workordername"] = Xrm.Page.getAttribute("new_requestname").getValue();
// 为日期类型字段进行赋值
parameters["new_receiving_date"] = "2015-11-15 16:00:00.000";
// 或者
parameters["new_receiving_date"] = Xrm.Page.getAttribute("new_expected_date").getValue().toDateString();
// 为选项集类型字段进行赋值
parameters["new_type"] = Xrm.Page.getAttribute("new_type").getValue();
// 打开实体Form
Xrm.Utility.openEntityForm("new_serviceworkorder", null, parameters);
}
Note:
因为最后会拼接成url字符串,所以赋值时不能直接赋值为object.必须转化为字符串。
例如对日期类型的赋值。
在调用这个方法时通常会出现下面这个错误。
觉得很奇怪,调查之后发现在我们调用 Xrm.Utility.openEntityForm(“new_serviceworkorder”, null, parameters);方法时,最后会把我们传递的参数都拼接成URL字符串,而通常浏览器会对URL的长度有最大限制。
解决方案可以参考下面这个链接:
http://www.cnblogs.com/luchaocai/p/3182510.html
微软官方给出的方案如下:
RESOLUTION
To resolve this problem, follow these steps:
Click Start, type Notepad in the Start Search box, right-click Notepad, and then click Run as administrator.
Note If you are prompted for an administrator password or for a confirmation, type the password, or click Continue.
On the File menu, click Open, type %windir%\System32\inetsrv\config\applicationHost.config in the File name box, and then click Open.
In the ApplicationHost.config file, locate the requestLimits tag.
Remove the maxQueryString property. Or, change the value to a value that matches the length of the query string that you are using. By default, the value of the maxQueryString property is 2048.
For example, modify the following code.
Save the ApplicationHost.config file.