-1

I was trying to run a workflow from ribbon button in grid:

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);
}

But it did throw an exception: GenerateAuthenticationHeader() is undefined

Filburt
  • 17,626
  • 12
  • 64
  • 115
Mostafa Moatassem
  • 351
  • 3
  • 11
  • 23
  • Well the error message seems pretty obvious: Did you verify that the function `GenerateAuthenticationHeader` is defined within the context of your Ribbon Button script? It will not work if you included the script to the entity form because those form scripts are loaded independently from the Ribbon. – Filburt Dec 30 '13 at 23:41

1 Answers1

0

Instead of using the GenerateAuthenticationHeader(), try using the following code:

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

Or if it doesn't work, create the authentication header manually

<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>
Anupam
  • 1,821
  • 3
  • 23
  • 41