Dynamics crm 子网格fetchXML javascript刷新未显示链接实体列
我在表单上有一个子网格,我正试图根据表单数据使用动态fetchXML刷新它。fetch正在适当地刷新子网格,但是链接实体列要么没有提取数据,要么子网格没有显示数据。这是我正在运行的javascriptDynamics crm 子网格fetchXML javascript刷新未显示链接实体列,dynamics-crm,dynamics-crm-2013,Dynamics Crm,Dynamics Crm 2013,我在表单上有一个子网格,我正试图根据表单数据使用动态fetchXML刷新它。fetch正在适当地刷新子网格,但是链接实体列要么没有提取数据,要么子网格没有显示数据。这是我正在运行的javascript function UpdateContactSubGrid() { //If this method is called from the Onload, make sure the grid is loaded before proceeding if (document
function UpdateContactSubGrid() {
//If this method is called from the Onload, make sure the grid is loaded before proceeding
if (document.getElementById('new_Opportunity_Contacts_SubGrid') == null) {
//The subgrid hasn't loaded, wait 1 second and then try again
setTimeout(UpdateContactSubGrid, 1000);
return;
}
// To get the Id of the 'Contacts' subgrid
var grid = document.getElementById('new_Opportunity_Contacts_SubGrid').control;
var fetchXML = "";
// To get contract lookup from 'CustomerId' field
var accountLookup = getAttributeValue("customerid");
if (accountLookup != null)
{
fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='new_affiliation'>" +
"<attribute name='new_role' />" +
"<attribute name='new_contactid' />" +
"<attribute name='new_affiliationid' />" +
"<order attribute='new_contactid' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='statecode' operator='eq' value='0' /> " +
"<condition attribute='new_clientid' operator='eq' value='" + accountLookup[0].id + "' />" +
"</filter>" +
"<link-entity name='contact' from='contactid' to='new_contactid' alias='a_adbe31a68306e2118bc478e3b5100e8d'>" +
"<attribute name='emailaddress1' />" +
"<attribute name='telephone1' />" +
"<attribute name='mobilephone' />" +
"</link-entity>" +
"</entity>" +
"</fetch>";
}
else
{
fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='new_affiliation'>" +
"<attribute name='new_role' />" +
"<attribute name='new_contactid' />" +
"<attribute name='new_affiliationid' />" +
"<order attribute='new_contactid' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='statecode' operator='eq' value='0' /> " +
"</filter>" +
"<link-entity name='contact' from='contactid' to='new_contactid' alias='a_adbe31a68306e2118bc478e3b5100e8d'>" +
"<attribute name='emailaddress1' />" +
"<attribute name='telephone1' />" +
"<attribute name='mobilephone' />" +
"</link-entity>" +
"</entity>" +
"</fetch>";
}
if (grid.SetParameter)
//Inject the new fetchXml
grid.SetParameter("fetchXml", fetchXML);
else
grid.get_innerControl().setParameter("fetchXml", fetchXML);
//Force the subgrid to refresh
grid.refresh();
}
// parametrs:
// attributeName: the name of the attribute
//purpose:
//It checks the existance of the attribute on the form and then get the value of the attriute.It applies null checks.
function getAttributeValue(attributeName) {
try {
var returnValue = null;
var attrb = Xrm.Page.getAttribute(attributeName);
if (attrb != null) {
{
var attrbValue = attrb.getValue();
if (attrbValue != null)
returnValue = attrbValue;
}
}
return returnValue;
}
catch (ex) {
alert(ex.message + ' ' + ex.name);
}
}
函数UpdateContactSubGrid(){
//如果从Onload调用此方法,请确保在继续之前加载网格
if(document.getElementById('new\u Opportunity\u Contacts\u SubGrid')==null){
//子网格尚未加载,请等待1秒钟,然后重试
setTimeout(UpdateContactSubGrid,1000);
返回;
}
//获取“联系人”子网格的Id
var grid=document.getElementById('new\u Opportunity\u Contacts\u SubGrid')。控件;
var fetchXML=“”;
//从“CustomerId”字段获取合同查找
var accountLookup=getAttributeValue(“customerid”);
if(accountLookup!=null)
{
fetchXML=“”+
"" +
"" +
"" +
"" +
"" +
"" +
" " +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"";
}
其他的
{
fetchXML=“”+
"" +
"" +
"" +
"" +
"" +
"" +
" " +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"";
}
if(grid.SetParameter)
//注入新的fetchXml
SetParameter(“fetchXml”,fetchXml);
其他的
grid.get_innerControl().setParameter(“fetchXml”,fetchXml);
//强制子栅格刷新
grid.refresh();
}
//参数:
//attributeName:属性的名称
//目的:
//它检查表单上属性的存在性,然后获取属性的值。它应用空检查。
函数getAttributeValue(attributeName){
试一试{
var returnValue=null;
var attrb=Xrm.Page.getAttribute(attributeName);
如果(attrb!=null){
{
var attrbValue=attrb.getValue();
if(attrbValue!=null)
returnValue=属性值;
}
}
返回值;
}
捕获(ex){
警报(例如消息+“”+例如名称);
}
}
实体之间的关系类型是什么? 使用N:N时,需要在链接实体节点中指示intersect=“true”。 使用N:1可以将link type=“outer”属性添加到链接实体节点
作为一个侧重点,考虑动态地编写FETCHXML,即
var fetchXML =
fetch()
.entity("new_affiliation")
.attributes("new_role", "new_contactid", "new_affiliationid")
.order("new_contactid", fetch.order.Asc)
.filter()
.condition("statecode", fetch.op.Equal, 0);
if (accountLookup != null) {
fetchXML = fetchXML
.condition("new_clientid", fetch.op.Equal, accountLookup[0].id);
}
fetchXML = fetchXML
.link({
entityName: "contact",
to: "new_contactid",
from: "contactid",
alias : "a_adbe31a68306e2118bc478e3b5100e8d",
type: fetch.link.outer //added outer join
})
.attributes("emailaddress1", "telephone1", "mobilephone")
return fetchXML.toString();
您可以在我的博客上找到有关使用DynamicFetchXMLBuilder的更多信息
嗯