我在表单上有一个子网格,我试图使用动态fetchXML刷新,具体取决于表单数据。 fetch正在刷新subGrid,但是链接实体列要么没有提取数据,要么subGrid没有显示它。这是我的javascript正在运行。
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);
}
}
答案 0 :(得分:0)
实体之间的关系类型是什么? 使用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();
您可以在我的博客上找到有关使用Dynamic FetchXMl构建器的更多信息 http://totbcrm.blogspot.com/2014/08/building-fetchxml-dynamically.html
HTH