0

我正在使用 CRM Dynamics。有一个 JavaScript 使用 ActiveXObject 来解析请求,但我需要将其转换为 Fetch Request。

旧代码是这样的:

function fnSetStateActiveQuoteRequest() {
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>" +
"    <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
"      <Request xsi:type=\"SetStateQuoteRequest\">" +
"        <EntityId>" + Xrm.Page.data.entity.getId() + "</EntityId>" +
"        <QuoteState>Active</QuoteState>" +
"        <QuoteStatus>2</QuoteStatus>" +
"      </Request>" +
"    </Execute>" +
"  </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/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

我正在尝试将其转换为:

var _oService; 
var _sOrgName = "myOrg"; 
var _sServerUrl = Xrm.Page.context.getServerUrl();
function fnSetStateActiveQuoteRequest(){
var sFetch = '<fetch mapping="logical">';
 sFetch+=  '<entity name='+Xrm.Page.data.entity.getId()'>';
 sFetch+=  '</filter>';
 sFetch+=  '</entity>';
 sFetch+= '</fetch>';

 _oService = new FetchUtil(_sOrgName, _sServerUrl);
 var oEntity = _oService.Fetch(sFetch, myCallBack); 
} 

但我不知道如何声明 Request> 和 QuoteState>

4

1 回答 1

1

您遇到的问题是您正在查看的第一个 XML 是执行请求的序列化版本。Fetch 更像是一种查询语言,因此您的编写方式略有不同。

弄清楚 fetch xml 需要是什么样子的最简单方法是打开高级查找并手动执行搜索。高级查找为您提供了一个“下载 Fetch XML”按钮,为您省去编写所有 fetch 的麻烦!

因此,旧查询看起来像是在尝试返回实体“X”的所有记录,其中它处于活动状态并且状态原因为 2。如果我在高级查找中编写类似的内容(假设我正在寻找机会)我的查询可能如下所示:

<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
  <entity name='opportunity'>
    <attribute name='name' />
    <attribute name='customerid' />
    <attribute name='estimatedvalue' />
    <attribute name='opportunityid' />
    <order attribute='name' descending='false' />
    <filter type='and'>
      <condition attribute='statecode' operator='eq' value='0' />
      <condition attribute='statuscode' operator='eq' value='2' />
    </filter>
  </entity>
</fetch>

这几乎是高级查找的下载获取 XML 的复制和粘贴。

于 2013-01-29T22:07:40.103 回答