【问题标题】:Retrieve the records of the other entities based on relation 1:N根据关系 1:N 检索其他实体的记录
【发布时间】:2015-03-16 20:57:45
【问题描述】:

下面的代码有助于从帐户实体的查找cs24_erpaccounttomergeid 中检索数据到我们刚刚创建的帐户。 我的问题是如何根据与同一查找 cs24_erpaccounttomergeid 相关的关系 1:N 检索其他实体的记录?

    if (crmForm.all.cs24_erpaccounttomergeid.DataValue != null)
{
  var l = crmForm.GetLookup('cs24_erpaccounttomergeid');
  var  ERPS = GetERPSourceName(l.id);
  if (ERPS == null)
  {

     crmForm.all.cs24_erpaccounttomergeid.DataValue = null;
  } 
}

// ERP SrourceName retrieve ==============
function GetERPSourceName(Act) {
    var xml = "" +
 "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
 GenerateAuthenticationHeader() +
 "<soap:Body>" +
"<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query'" +
" xsi:type='q1:QueryExpression'>" +
"<q1:EntityName>account</q1:EntityName>" +
"<q1:ColumnSet xsi:type='q1:ColumnSet'>" +
"<q1:Attributes>" +
"<q1:Attribute>cs_erpsourcename</q1:Attribute>" +
"</q1:Attributes>" +
"</q1:ColumnSet>" +
"<q1:Distinct>false</q1:Distinct>" +
"<q1:Criteria>" +
"<q1:FilterOperator>And</q1:FilterOperator>" +
"<q1:Conditions>" +
"<q1:Condition>" +
"<q1:AttributeName>accountid</q1:AttributeName>" +
"<q1:Operator>Equal</q1:Operator>" +
"<q1:Values>" +
"<q1:Value xsi:type='xsd:string'>" + Act + "</q1:Value>" +
"</q1:Values>" +
"</q1:Condition>" +
"</q1:Conditions>" +
"</q1:Criteria>" +
"</query>" +
"</RetrieveMultiple>" +
"</soap:Body>" +
"</soap:Envelope>" +
 "";

    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction", " http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);

    var resultXml = xmlHttpRequest.responseXML;
    var Request = resultXml.getElementsByTagName("BusinessEntity");
if (Request.length == 0)   return null;
else
{
  if (Request[0].getElementsByTagName("q1:cs_erpsourcename")[0] != null)
   {
      var ERPSourceName = resultXml.selectNodes("//BusinessEntity/q1:cs_erpsourcename");
       return ERPSourceName[0].text;
    }
    else return null;

 }
}

有人可以帮我实现这个目标吗!? 谢谢你的时间

【问题讨论】:

    标签: javascript web-services dynamics-crm-2011 dynamics-crm dynamics-crm-4


    【解决方案1】:

    我建议首先迁移您的代码以使用通用库来生成 XML 请求。 XrmServiceToolkit 是一种常用的工具。一旦你使用了它,调用 RetrieveMultiple 就简单多了。

    https://xrmservicetoolkit.codeplex.com/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      • 2012-11-28
      • 2013-12-08
      • 2023-03-24
      相关资源
      最近更新 更多