locked
Run Workflow FRom Button RRS feed

  • Question

  • Hi

    I Have 2 question

    1- i have a button in rebbon

    in action i write the url of workflow form

    in show this with moadl or window

    but when i click on button

    the workflow was not run

    so why ?

    and if i run workflow form from button what do i do?

    2- How Can I RUn Workflow from js

    in this way i want to create function and call it from button to run wf

    Please Help Me


    AME

    Tuesday, March 11, 2014 11:05 AM

All replies

  • Can you try this.

    - Create a two Option Field (Boolean)

    - Create a custom JavaScript code that changes the value on the field and add it to a ribbon button trigger.

         - Run WorkFlow on field change.

    This works. Not sure if it is the best solution but it is a working one.

    Good Luck :)

    Tuesday, March 11, 2014 11:12 AM
  • JavaScript to execute a workflow would look something like this - you will need to GUID of the workflow to be executed:

    function ExecuteWorkflowSOAP() {
        var workflowId = "99999999-9999-9999-9999-999999999999";
        var request = [
            "<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/'>" + Xrm.Page.data.entity.getId() + "</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/'>" + workflowId + "</c:value>",
    							"</a:KeyValuePairOfstringanyType>",
    						"</a:Parameters>",
    						"<a:RequestId i:nil='true' />",
    						"<a:RequestName>ExecuteWorkflow</a:RequestName>",
    					"</request>",
    				"</Execute>",
    			"</s:Body>",
            "</s:Envelope>"
        ];
    
        var req = new XMLHttpRequest();
        req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", true);
    
        try {
            req.responseType = 'msxml-document';
        } catch (e) {}
        req.setRequestHeader("Accept", "application/xml, text/xml, */*");
        req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
        req.onreadystatechange = function () {};
        req.send(request.join(""));
    }
    


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Tuesday, March 11, 2014 12:48 PM
    Moderator
  • I Run Thos Code

    But

    Workflow Not Run

    And No Error Show


    AME

    Tuesday, March 11, 2014 1:22 PM
  • Hi

    Please check the following link...

    Run a workflow using JavaScript in CRM 2011

    --

    Regards,

    Gopinath.

    http://mscrmtechie.blogspot.com/

    Thursday, March 13, 2014 9:12 AM