在Microsoft Dynamic CRM 2011中使用Javascript填充时,查找字段未保存
关于Microsoft Dynamics CRM 2011: 如果我使用Javascript设置查找字段的值,它会正确显示在表单上(名称、图标等),但在用户点击保存按钮时不会保存。记录不会保存,只是不会保存该字段。如果我“手动”执行(即使用查找控件),它将保存字段值 由于某些原因,它在窗体的“保存时”事件中工作,但在窗体的“保存并关闭时”事件中不工作。 有什么想法吗 代码如下:在Microsoft Dynamic CRM 2011中使用Javascript填充时,查找字段未保存,javascript,dynamics-crm-2011,crm,lookup,Javascript,Dynamics Crm 2011,Crm,Lookup,关于Microsoft Dynamics CRM 2011: 如果我使用Javascript设置查找字段的值,它会正确显示在表单上(名称、图标等),但在用户点击保存按钮时不会保存。记录不会保存,只是不会保存该字段。如果我“手动”执行(即使用查找控件),它将保存字段值 由于某些原因,它在窗体的“保存时”事件中工作,但在窗体的“保存并关闭时”事件中不工作。 有什么想法吗 代码如下: //Fetching the required accountId using REST method functio
//Fetching the required accountId using REST method
function fetchAccountId() {
try
{
var LE;
var Fund;
var LEId = new Array();
LEId = Xrm.Page.getAttribute('ssi_legalentityid').getValue();
if (LEId != null) {
LE = LEId[0].id;
}
var FundId = new Array();
FundId = Xrm.Page.getAttribute('ssi_fundid').getValue();
if (FundId != null) {
Fund = FundId[0].id;
}
var LEId = Xrm.Page.getAttribute('ssi_legalentityid').getValue();
var FundId = Xrm.Page.getAttribute('ssi_fundid').getValue();
var TransactionType = Xrm.Page.getAttribute('ssi_transactiontypes').getValue();
if (LEId != null && FundId != null && TransactionType == '6')
{
var options = "$select=ssi_AccountId,ssi_name&$filter=Ssi_LegalEntityId/Id eq (guid'"+LE+"') and Ssi_FundId/Id eq (guid'"+Fund+"')";
SDK.REST.retrieveMultipleRecords('ssi_Account', options, saved, err, contactsRetrieveComplete);
}
}
catch (Err) {
alert(Err);
return;
}
}
function saved(ssi_account)
{
if (ssi_account != null && ssi_account.length > 0)
{
var fetchedAccId;
for (var i = 0; i < ssi_account.length; i++)
{
fetchedAccId = ssi_account[i].ssi_AccountId;
fetchedName = ssi_account[i].ssi_name;
}
var Contact_Lookup = new Array();
Contact_Lookup[0] = new Object();
Contact_Lookup[0].id = fetchedAccId;
Contact_Lookup[0].name = fetchedName;
Contact_Lookup[0].entityType = 'ssi_Account';
Xrm.Page.getAttribute('ssi_accountid').setValue(Contact_Lookup);
Xrm.Page.data.entity.save();
}
}
function err(error){
alert('Error occurred while fetching the details of the Client Account. '+error.message);
}
function contactsRetrieveComplete() {
}
//使用REST方法获取所需的accountId
函数fetchAccountId(){
尝试
{
var-LE;
var基金;
var LEId=新数组();
LEId=Xrm.Page.getAttribute('ssi_legalentityid').getValue();
如果(LEId!=null){
LE=LEId[0].id;
}
var FundId=新数组();
FundId=Xrm.Page.getAttribute('ssi_FundId').getValue();
如果(FundId!=null){
Fund=FundId[0].id;
}
var LEId=Xrm.Page.getAttribute('ssi_legalentityid').getValue();
var FundId=Xrm.Page.getAttribute('ssi_FundId').getValue();
var TransactionType=Xrm.Page.getAttribute('ssi_transactiontypes').getValue();
如果(LEId!=null&&FundId!=null&&TransactionType=='6')
{
var options=“$select=ssi_AccountId,ssi_name&$filter=ssi_LegalEntityId/Id eq(guid'+LE+”)和ssi_FundId/Id eq(guid'+Fund+”)”;
SDK.REST.retrieveMultipleRecords('ssi_帐户',选项,已保存,错误,联系人RetrieveComplete);
}
}
捕捉(错误){
警惕(Err);
返回;
}
}
保存的功能(ssi_帐户)
{
if(ssi_account!=null&&ssi_account.length>0)
{
var-fetchedAccId;
对于(变量i=0;i
在CRM表单的保存事件中调用上述代码。尝试更改行
Contact_Lookup[0].entityType = 'ssi_Account';
排队
Contact_Lookup[0].entityType = 'ssi_account';
您的代码使用CRM SDK函数
retrieveMultipleRecords
检索存储的数据,以下是哪个签名:
函数(类型、选项、successCallback、errorCallback、OnComplete)
代码将saved
函数传递给successCallback
参数。异步调用保存的
函数。在保存场景中,这是可以的,但在保存和关闭场景中,在retrieveMultipleRecords
能够接收查询的数据之前,表单将关闭并释放其脚本
您的代码必须同步运行才能成功
在SDK.REST
库的RetrieveMultipleRecords
函数中,您可以找到以下行:
var req = new XMLHttpRequest();
req.open("GET", this._ODataPath() + type + "Set" + optionsString, true);
将最后一个
true
更改为false
。这将使功能进入同步模式。你好,Henk van Boeijen,感谢您的回复。您是对的,保存的代码是异步调用的。如何使代码在表单的“保存和关闭”事件中同步运行?我扩展了我的答案。嗨,Henk van Boeijen,我将尝试一下……谢谢!