从功能区按钮运行工作流程

时间:2013-12-30 23:31:32

标签: dynamics-crm crm dynamics-crm-2013

我试图从网格中的功能区按钮运行工作流程:

function TriggerWorkflow(entityId, workflowGuid)
{
    debugger;
    /*Generate Soap Body.*/
    var soapBody = "<soap:Body>" +
                   "  <Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
                   "    <Request xsi:type=\'ExecuteWorkflowRequest\'>" +
                   "      <EntityId>" + entityId + "</EntityId>" +
                   "      <WorkflowId>" + workflowGuid + "</WorkflowId>" +
                   "    </Request>" +
                   "  </Execute>" +
                   "</soap:Body>";

    /*Wrap the Soap Body in a soap:Envelope.*/
    var soapXml = "<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() +
                  soapBody +
                  "</soap:Envelope>";

    /* Create the XMLHTTP object for the execute method.*/
    var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    xmlhttp.open("POST", "/MSCRMservices/2007/crmservice.asmx", false);
    xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");

    /* Send the XMLHTTP object. */
    xmlhttp.send(soapXml);
}

但确实引发了异常: GenerateAuthenticationHeader()未定义

1 个答案:

答案 0 :(得分:0)

请尝试使用以下代码,而不是使用GenerateAuthenticationHeader()

var context = GetGlobalContext();
var header = context.getAuthenticationHeader();

如果它不起作用,请手动创建身份验证标头

<soap:Header>
<CrmAuthenticationToken xmlns="http://schemas.microsoft.com/crm/2007/WebServices">
  <AuthenticationType xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
    0
  </AuthenticationType>
  <OrganizationName xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
    AdventureWorksCycle
  </OrganizationName>
  <CallerId xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
    00000000-0000-0000-0000-000000000000
  </CallerId>
</CrmAuthenticationToken>
</soap:Header>