Triggering a Workflow from a Ribbon Button

Add Button to Entity Ribbon

Export the entity in question and open up customizations.xml. Add the following within the CustomActions tag…

      LabelText="Button Label"
      ToolTipTitle="Run Test Workflow"
      ToolTipDescription="Runs the test workflow to see if this works"
      Image32by32="/_imgs/ribbon/tools_32.png" />

Location sets which area of the ribbon the button will appear on.
Sequence sets where within that ribbon it will appear.
LabelText sets the text which appears under the icon on the ribbon.
TemplateAlias (who knows!)

Create the click action

Now we need to add the command Mscrm.RunSomeJS within the CommandDefinitions section.

    <EnableRule Id="Mscrm.Enabled" />
    <DisplayRule Id="Mscrm.CanWriteAccount" />
        Value="{guid of account entity}" />
        Value="{7D78531A-23EB-4042-9626-1D80DFC10A8D}" />

EnableRules sets if the button is greyed out on the toolbar (always enabled in this example)
DisplayRules sets if the button appears on the toolbar (if the user can write to the account entity in this example)
FunctionName sets the name of the function to run within the web resource
Library sets the name of the web resource JavaScript library to access
in this case are the guid of the account entity (not used currently) and the guid of the workflow to trigger

JavaScript to Fire the Workflow

function TriggerWorkflow(entityName,workflowGuid) {

  var xx = prompt(,;

  /*Generate Soap Body.*/
  var soapBody = "<soap:Body>" +
                 "  <Execute xmlns=''>" +
                 "    <Request xsi:type=\'ExecuteWorkflowRequest\'>" +
                 "      <EntityId>" + + "</EntityId>" +
                 "      <WorkflowId>" + workflowGuid + "</WorkflowId>" +
                 "    </Request>" +
                 "  </Execute>" +

  /*Wrap the Soap Body in a soap:Envelope.*/
  var soapXml = "<soap:Envelope " +
                "  xmlns:soap='' " +
                "  xmlns:xsi='' " +
                "  xmlns:xsd=''>" +
                GenerateAuthenticationHeader() +
                soapBody +

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

  /* Send the XMLHTTP object. */