web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Workflow: Do you really want to execute

(0) ShareShare
ReportReport
Posted on by 423

I created a custom button "Spam" that executes a workflow in the entity mail. But every time users click on it, they are asked if they really want to run it.

Is there a parameter or argument I can send with the ribbon workbench to prevent the CRM 2011 from doing this and execute the workflow right after clicking the button?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Bernhard,

    See the community thread below.

    community.dynamics.com/.../193211

  • Suggested answer
    Andreas Cieslik Profile Picture
    9,267 on at

    Hello Bernhard,

    I assume you followed this guide to add and confiugre the custom button:

    ribbonworkbench.uservoice.com/.../132235-create-a-workflow-short-cut-ribbon-button-no-code

    This guide will use built-in functionality to start a workflow with a prompt that you don't want.

    To Workaround this you need to apply some modifications:

    In step 10 you need to call your own JavaScript library/function similar to the link below:

    meghshyam.wordpress.com/.../triggerexecute-workflow-using-javascript-in-crm-2011crm-2013

    This approach would directly start the workflow without asking the using with a prompt.

    Cheers,

    Andreas

  • bernhards Profile Picture
    423 on at

    Hi Andreas,

    thanks for your answer. I tried your script but unfortunately it is creating a strange error:

    3288.crmerror.png

    This is the code I used:

    // Main function to be called from Ribbon button to execute the workflow
    function ExecuteWorkflowFromRibbonButton(workflowId) {
    //Get workflow id by passing the workflow name as parameter
    var workflowId = workflowId;
    if (workflowId != null) {
    // Get record id
    var entityId = Xrm.Page.data.entity.getId();
    //Function for executing the workflow
    startWorkflow(entityId, workflowId);
    }
    }

    function startWorkflow(entityId, workflowId) {
    try {
    var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
    var serverUrl = "";
    if (typeof GetGlobalContext == "function") {
    var context = GetGlobalContext();
    serverUrl = context.getServerUrl();
    }
    else {
    if (typeof Xrm.Page.context == "object") {
    serverUrl = window.location.protocol + "//" + window.location.host + "//" + Xrm.Page.context.getOrgUniqueName();
    alert(serverUrl );
    serverUrl = Xrm.Page.context.getServerUrl();
    alert(serverUrl );
    }
    else { throw new Error("Unable to access the server URL"); }
    }
    if (serverUrl.match(/\/$/)) {
    serverUrl = serverUrl.substring(0, serverUrl.length - 1);
    }

    serverUrl = serverUrl + OrgServicePath;
    var requestMain = ""
    requestMain += "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">";
    requestMain += " <s:Body>";
    requestMain += " <Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">";
    requestMain += " <request i:type=\"b:ExecuteWorkflowRequest\" xmlns:a=\"schemas.microsoft.com/.../Contracts\" xmlns:b=\"schemas.microsoft.com/.../Contracts\">";
    requestMain += " <a:Parameters xmlns:c=\"schemas.datacontract.org/.../System.Collections.Generic\">";
    requestMain += " <a:KeyValuePairOfstringanyType>";
    requestMain += " <c:key>EntityId</c:key>";
    requestMain += " <c:value i:type=\"d:guid\" xmlns:d=\"schemas.microsoft.com/.../Serialization\">" + entityId + "</c:value>";
    requestMain += " </a:KeyValuePairOfstringanyType>";
    requestMain += " <a:KeyValuePairOfstringanyType>";
    requestMain += " <c:key>WorkflowId</c:key>";
    requestMain += " <c:value i:type=\"d:guid\" xmlns:d=\"schemas.microsoft.com/.../Serialization\">" + workflowId + "</c:value>";
    requestMain += " </a:KeyValuePairOfstringanyType>";
    requestMain += " </a:Parameters>";
    requestMain += " <a:RequestId i:nil=\"true\" />";
    requestMain += " <a:RequestName>ExecuteWorkflow</a:RequestName>";
    requestMain += " </request>";
    requestMain += " </Execute>";
    requestMain += " </s:Body>";
    requestMain += "</s:Envelope>";

    var req = new XMLHttpRequest();
    req.open("POST", serverUrl, false)
    // Responses will return XML. It isn’t possible to return JSON.
    req.setRequestHeader("Accept", "application/xml,text/xml,*/*");
    req.setRequestHeader("Content-Type", "text/xml;charset=utf-8");
    req.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute&amp;#8221;");

    req.send(requestMain);

    alert("Workflow execution Completed.");
    }
    catch (e) {
    alert(e.message.toString());
    }

    }
    //Function to get the workflow id
    function GetWorkflowIDByName(wfName) {
    //debugger;
    var objFilteredWF = null;
    var serverUrl = Xrm.Page.context.getServerUrl();
    //Prepare ODATA query to fetch WF GUID by WF Name
    var odataSelect = serverUrl + "/xrmservices/2011/OrganizationData.svc/WorkflowSet?$select=WorkflowId&$filter=ActiveWorkflowId/Id ne null and Name eq ‘" + wfName + "‘";
    $.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: odataSelect,
    beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
    success: function (data, textStatus, XmlHttpRequest) {
    objFilteredWF = data.d;
    },
    error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
    });
    var wfID = null;
    if (objFilteredWF != null && objFilteredWF.results != null && objFilteredWF.results.length != 0 && objFilteredWF.results[0].WorkflowId != null) {
    wfID = objFilteredWF.results[0].WorkflowId;
    }
    return wfID;

    }

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Bernhard,

    See the links below. They describe how to Execute Workflows in Microsoft Dynamics CRM 2011 using Javascript.

    msdn.microsoft.com/.../jj659838.aspx

    sliong.wordpress.com/.../crm-2011-runningexecuting-workflow-using-javascript/

    Hope this helps.

  • Community Member Profile Picture
    on at

    No better option but you have to create a custom ribbon button to execute the workflow instead of using the OOB run workflow button.

  • Andreas Cieslik Profile Picture
    9,267 on at

    It should be like this:

    req.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute");

    Can you use the debugging functionality of your browser to check where the error occurs?

    Are you using localhost in your Server Url?

    Are you able to manually open and validate the access of the serverUrl variable?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans