表格:实体A
表格:实体B
功能 当我在实体中选择审批者时:A并选择一个html按钮 我使用下面的代码将查询字符串发送到表单Entity:B
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD>
<SCRIPT type=text/javascript>
function setDelegate(){
var ApproverInfo = new Array();
ApproverInfo = window.parent.Xrm.Page.getAttribute('bch_approver').getValue();
if(ApproverInfo[0] != null)
{
var parameters = {};
parameters["formid"] = "{b053a39a-041a-4356-acef-ddf00182762b}";
window.parent.Xrm.Utility.openEntityForm("bch_delegate", ApproverInfoId );
}
}
</SCRIPT>
<META charset=utf-8></HEAD>
<BODY><INPUT onclick=setDelegate(); value="Set Delegate" type=submit> </BODY></HTML>
在表单实体:B页面加载中我编写了以下javascript代码来读取和设置实体中的查找:B
我使用以下代码收到了查询字符串:
// Get the Value of the Regarding through the Customer Parameters
var param=Xrm.Page.context.getQueryStringParameters();
if (param != null ) {
alert('inside');
var ApproverId=param["bch_signingauthority"];
var bchName = param["bch_name"];
//Populate the Regarding if there is one
//if (regardingId != undefined)
//{Xrm.Page.getAttribute("regardingobjectid").setValue([{id:regardingId, name:regardingName, entityType:regardingType}]);}
var a = GetApproverName(ApproverId);
var lookup = new Array();
lookup[0] = new Object();
lookup[0].id = bchName;
lookup[0].name = a;
//alert(a.trim());
//alert(ApproverId);
//lookup[0].entityType = 'Signing Authority';
//Xrm.Page.getAttribute('bch_signingauthority').setValue(lookup);
Xrm.Page.getAttribute("bch_signingauthority").setValue([{ id: bchName, name: a, entityType: 'Signing Authority'}]);
lookup[0] = new Object();
lookup[0].id = ApproverId;
lookup[0].name = a;
Xrm.Page.getAttribute('bch_approver_test1').setValue(lookup);
}
}
function GetApproverName(ApproverId) {
var result = "";
var serverUrl = document.location.href.substring(0, document.location.href.indexOf("/", 10));
var organizationName = Xrm.Page.context.getOrgUniqueName();
serverUrl = serverUrl + "/" + organizationName;
var fetchUtil = new FetchUtil(organizationName, serverUrl);
var _fetchXMLGetUserName = ""
+ " <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> "
+ " <entity name='systemuser'> "
+ " <attribute name='fullname'/> "
+ " <attribute name='systemuserid'/> "
//+ " <attribute name='createdon' /> "
//+ " <attribute name='bch_approver' /> "
+ " <order attribute='fullname' descending='false' /> "
+ " <filter type='and'> "
+ " <condition attribute='systemuserid' operator='eq' uitype='systemuser' value='"
+ ApproverId + " ' />"
+ " </filter> "
+ " </entity> "
+ " </fetch> ";
alert(_fetchXMLGetUserName );
try {
// Find System User
var systemUser = fetchUtil.Fetch(_fetchXMLGetUserName);
if (systemUser && systemUser.length > 0) {
// var signingAuthority = systemUser[0].attributes["bch_signingauthorityid"];
// alert(signingAuthority.value);
// var name = systemUser[0].attributes["bch_name"];
// alert(name.value);
var systemUserName = systemUser[0].attributes["fullname"];
// alert(systemUserName.value);
if ((systemUserName != null) && (systemUserName.value != null)) {
result = systemUserName.value;
}
}
}
catch (e) { alert('An Error occured in GetUserName'); }
return result;
}
我无法设置审批者查找/名称:bch_signingauthority 通过查询字符串传入的ID。你能帮忙并建议我如何去做这件事,因为我对CRM Dynamics 2011还不熟悉。
答案 0 :(得分:60)
您的.setValue()
调查查询属性存在一些问题。
我建议使用this helper function form the CRM SDK:
function setSimpleLookupValue(LookupId, Type, Id, Name) {
var lookupReference = [];
lookupReference[0] = {};
lookupReference[0].id = Id;
lookupReference[0].entityType = Type;
lookupReference[0].name = Name;
Xrm.Page.getAttribute(LookupId).setValue(lookupReference);
}
使用该功能转换:
Xrm.Page.getAttribute("bch_signingauthority").setValue([{ id: bchName, name: a, entityType: 'Signing Authority'}]);
到
setSimpleLookupValue('bch_signingauthority', 'Signing Authority', bchName, a);
下一个问题是您的代码使用"Signing Authority"
作为entityType
。这不是有效的entityType
,它应该是Lookup引用的实体的逻辑名称。在此,我认为bch_signingauthority
是SystemUser
的查找,因此它应该是'systemuser'
,因此如下所示:
setSimpleLookupValue('bch_signingauthority', 'systemuser', bchName, a);