Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Workflow: Do you really want to execute

Posted on by 417

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

  • Andreas Cieslik Profile Picture
    Andreas Cieslik 9,265 on at
    RE: Workflow: Do you really want to execute

    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?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Workflow: Do you really want to execute

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

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Workflow: Do you really want to execute

    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.

  • bernhards Profile Picture
    bernhards 417 on at
    RE: Workflow: Do you really want to execute

    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
    Andreas Cieslik Profile Picture
    Andreas Cieslik 9,265 on at
    RE: Workflow: Do you really want to execute

    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

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Workflow: Do you really want to execute

    Hi Bernhard,

    See the community thread below.

    community.dynamics.com/.../193211

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans