2012-07-18 21 views
5

में जावास्क्रिप्ट से वर्कफ़्लो निष्पादित करें मैं एक रिबन बटन के माध्यम से दृश्य में चयनित रिकॉर्ड्स के लिए वर्कफ़्लो निष्पादित करने का प्रयास कर रहा हूं।सीआरएम 2011

function invokeWorkflow(workflowId, entityId) { 
    var request = 
     '<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="ExecuteWorkflowRequest">' + 
     '  <EntityId>' + entityId + '</EntityId>' + 
     '  <WorkflowId>' + workflowId + '</WorkflowId>' + 
     '  </Request>' + 
     ' </Execute>' + 
     ' </soap:Body>' + 
     '</soap:Envelope>'; 

    var xhr = new XMLHttpRequest(); 
    xhr.open('POST', '/MSCRMservices/2007/crmservice.asmx', false); 

    xhr.setRequestHeader('Content-Type', 'text/xml; charset=utf-8'); 
    xhr.setRequestHeader('SOAPAction', 'http://schemas.microsoft.com/crm/2007/WebServices/Execute'); 

    xhr.send(request); 
} 

हालांकि, मैं भविष्य रिलीज के लिए यह रख-रखाव CRM 2011 के सेवाओं का उपयोग को बढ़ाने के लिए लिखना चाहते हैं: मैं एक काम कर उदाहरण सीआरएम 4 संगतता के लिए 'विरासत' सेवाओं का उपयोग कर सकते है। यहां तक ​​कि मैंने अभी तक कोशिश की है, लेकिन यह काम नहीं करता है - कॉल का रिटर्न कोड HTTP 500 (आंतरिक सर्वर त्रुटि) है।

function invokeWorkflow(workflowId, entityId) { 
    var request = 
     '<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">' + 
     ' <soap:Body>' + 
     ' <Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">' + 
     '  <Request xsi:type="ExecuteWorkflowRequest">' + 
     '  <EntityId>' + entityId + '</EntityId>' + 
     '  <WorkflowId>' + workflowId + '</WorkflowId>' + 
     '  </Request>' + 
     ' </Execute>' + 
     ' </soap:Body>' + 
     '</soap:Envelope>'; 

    var xhr = new XMLHttpRequest(); 
    xhr.open('POST', '/XRMServices/2011/Organization.svc/web', true); 

    xhr.setRequestHeader('Accept', 'application/xml, text/xml, */*'); 
    xhr.setRequestHeader('Content-Type', 'text/xml; charset=utf-8'); 
    xhr.setRequestHeader('SOAPAction', 'http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute'); 

    xhr.onreadystatechange = function() { alert(xhr.status); }; 
    xhr.send(request); 
} 

क्या किसी को पता है कि दूसरी स्क्रिप्ट के साथ क्या गलत है? मैंने इसे जितना संभव हो उतना गुगलिंग करने का प्रयास किया है, लेकिन हर उदाहरण में मुझे लगता है कि सीआरएम 2011 के लिए कौन सा दावा होना चाहिए वास्तव में केवल सीआरएम 4 संगतता सेवाओं का उपयोग करना (जैसा कि पहले उदाहरण में है)। मैंने सीआरएम 2011 एसडीके में नमूने से दूसरा उदाहरण स्थापित किया है, हालांकि इसमें ExecuteWorkflowRequest ऑब्जेक्ट का उदाहरण शामिल नहीं है, इसलिए यह केवल सर्वोत्तम अनुमान है।

धन्यवाद!

उत्तर

7

सीआरएम एसडीके फ़ोल्डर \ samplecode \ cs \ client \ soaplogger में SOAPLogger नामक एक एप्लिकेशन है जो विशिष्ट कार्यों के लिए जावास्क्रिप्ट में अनुरोध उत्पन्न करता है।

नीचे, आप "ExecuteWorkflow" के लिए http अनुरोध प्राप्त कर सकते हैं (केवल EntityIdValue और WorkflowIdValue के लिए मान बदलें)।

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Body> 
    <Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
     <request i:type="b:ExecuteWorkflowRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts"> 
     <a:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"> 
      <a:KeyValuePairOfstringanyType> 
      <c:key>EntityId</c:key> 
      <c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">EntityIdValue</c:value> 
      </a:KeyValuePairOfstringanyType> 
      <a:KeyValuePairOfstringanyType> 
      <c:key>WorkflowId</c:key> 
      <c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">WorkflowIdValue</c:value> 
      </a:KeyValuePairOfstringanyType> 
     </a:Parameters> 
     <a:RequestId i:nil="true" /> 
     <a:RequestName>ExecuteWorkflow</a:RequestName> 
     </request> 
    </Execute> 
    </s:Body> 
</s:Envelope> 

XMLHttpRequest के निर्माण corect है, इसलिए soapEnvelope बदलने का प्रयास करें।