How to execute workflow through javascript in CRM 2013

Hi,
I have created a business process and I want to execute workflow on custom button through javascript. I tried this script but this script does not run after message box show. Please tell me how to execute my workflow through javascript
function RunWorkflow() {
    var _return = window.confirm('Are you want to execute workflow.');
    if (_return) {
        var url = Xrm.Page.context.getServerUrl();
        var entityId = Xrm.Page.data.entity.getId();
        var workflowId = '541B45C9-3F88-4448-9690-2D4A365C3172';
        var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
        url = url + OrgServicePath;
        var request;
        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/\">"
+ entityId + "</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", url, true)
        // 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", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
        req.onreadystatechange = function () { assignResponse(req); };
        req.send(request);
function assignResponse(req) {
    if (req.readyState == 4) {
        if (req.status == 200) {
            alert('successfully executed the workflow');

Hi,
I used this script for execute the workflow but its not working. When I used alert(req.status); then 500 show. Please tell me what did I mistake in my script.
function RunWorkflow() {
    var _return = window.confirm('Are you want to execute workflow.');
    if (_return) {
        var url = Xrm.Page.context.getClientUrl();
        var entityId = Xrm.Page.data.entity.getId();
        var workflowId = '541B45C9-3F88-4448-9690-2D4A365C3172';
        var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
        url = url + OrgServicePath;
        var request;
        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/\">"
+ entityId + "</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", url, true)
        // 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", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
        req.onreadystatechange = function () { assignResponse(req); };
        req.send(request);
function assignResponse(req) {
    if (req.readyState == 4) {
alert(req.status);
        if (req.status == 200) {
            alert('successfully executed the workflow');

Similar Messages

  • Kindly send anybody a ppt on how to execute reports through Browser and Ana

    Hi all,
    I need a PPT on how to execute reports through Browser and Analyzer in version 3.5 or older to 3.5 immediatley from end user point of view. I donot have time to prepare it and has to be sumbmitted before end of the day.
    Kindly help me out by sending it [email protected] .
    Thanks in Advance.
    Anil Kumar Sharma .P

    Thank you Mr. Voodi,
    I will wait for your reply.
    Meanwhile could anybody else ,send me PPT on it.
    Thanks in Advance,
    Anil Kumar
    Message was edited by:
            Anil Kumar Sharma

  • How to execute an internal WebService from CRM On Demand?

    Hello,
    I would like to know how to execute an internal WebService, for example Contact's WebService, from CRM On Demand?
    I have seen in the online documentation:
    "An integration event is a mechanism for triggering external processes that are based on changes (create, update, delete, associate, dissociate) to the records in Oracle CRM On Demand.
    You can specify which fields on a record that you want to track. If your company wants to use workflow rules to create integration events, contact Customer Care to request support for Integration Event Administration and to specify the total size of the integration event queues that you require".
    I have this option activated. In fact, I have tried to create a workflow rule to assign an integration event to call the WebService process, but I couldn't do it...
    Thank you and regards.

    Hi, sorry for the late answer. I now understand what you are trying to do, it is an automatic approach so you will need to use integration events.
    So if custom object 2 field is changed you have to generate an integration event with a workflow that triggers when modified record is saved. The event should be transfered to the queue you defined.
    What you need is an external componenet e.g. java component that is running in an application server and polls every (let's say 30 seconds for events in the queue. If there is an event in the queue you will need the custom object 3 Id and the value for the field you would like to update and afterwards you can update the related customonject3 record with a ws call.
    If you use java you can start the timer with a servlet lifecycle event (when application is up start the timer for polling)
    Best Regards
    SL

  • How to execute workflow with pl/sql?

    My foregoing work has been done with owb including building dimension table, face table, mappings, and workflow process. if I don't install workflow server/client program module, how to execute the workflow process? Can PL/SQL do this and how to?

    user13726880 wrote:
    The original requirements were put together and given to me, an Oracle newbie. They expected the Java app to use something intrinsic to Oracle and Unix sendmail. To solve my problem, I use a JDBC connection to run some SQL commands. I take that data, format it and send the results by email to the user. By default the requirement is to send it as an HTML attachment using Unix 'sendmail'. So I do that using Runtime exec. I have also added JavaMail functionality as an alternative to sendmail. It works great and as expected.Sounds like a reasonable solution.
    Note however that PL/SQL itself can send email. And PL/SQL can call unix sendmail too.
    However myself I would have done it in java with JavaMail.

  • How to execute the InDesign Javascript from outside in MAC

    Hi All,
    I need to execute the InDesign Javascript from outside in MAC machine.
    Anyone can help me.
    Thanks in advance.
    Regards,
    Ramkumar

    If you just want to imitate double clicking a file, use execute() method, e.g.:
    var myJavaScriptFile = new File("~/Desktop/Test.jsx");
    myJavaScriptFile.execute();
    At the top of your .jsx file type #target indesign to make the script run in InDesign.
    And I want to add to what Harbs said in the previous post: when you use do script command, you can also send parameters and get back values. See DoScriptParameters and DoScriptReturnValues sample scripts from InDesign CS3 Guide Scripts for details.

  • How to execute FM from Javascript function?

    Hi All,
    I have a requirement to execute ABAP FM from Javascript function in BSP Application.
    How do I implement this?
    Is there any document/link in SDN?
    Thanks
    Thruna Shanmuga

    Hi,
    When button is clicked capture the event in OnInPutProcessing and call the function module.
    In layout mention the java code
    Here is a sample code:
    Layout Code:
    < script >
    document.on keydown=function( )
    if (event.key Code==13)
    htmlb SL(this,2,'get') Mention the button ID
    < /script >
      <htmlb:button id      = "get"
                             text    = "Execute"
                            width   = "35%"
                            on Click = "On InputProcessing()" />
    OnInPutProcessing Code:
    data:
      w_event type ref to cl_htmlb_event,
    call method cl_htmlb_manager=>get_event
      exporting
        request = runtime->server->request
      receiving
        event   = w_event.
    case w_event->id.(To capture the event)
    when 'get'.
    <<Call the function module>>
    endcase.
    Hope this solves the issue, Let me know if any queries.
    Regards,
    Rajani

  • Executing Workflow through RFC Call

    Hi,
        I need to execute a worklow in one system through an RFC call from another system . Is this possible?
    If yes, then what all parameteres do I need to do so and what all steps are involved.
    Regards,
    Divyanshu

    Hi Divyanshu,
    It is best not to start workflows directly but rather by using events. Usually a WF will have a triggering event defined, such as EMPLOYEET.POSITIONCHANGED. Look at the WF header for the trigger.
    You can remotely raise this event using FM SAP_WAPI_CREATE_EVENT. Pass it the object type, key and event name and any other parameters. It even has some documentation.
    Cheers
    Mike

  • How to execute vbscript through java

    hi i m trying to run vbscript (that accept some command line arguments) through java .
    my vbs file is stored in c: drive
    purpose of vbs file : to map network drives.
    i normally run it from command prompt using following syntax
    c:\cscript map.vbs l: \\10.22.122.35\d$ <username> <password>
    code in map.vbs
    map.vbs
    Dim objNetwork
    Set objNetwork = WScript.CreateObject("WScript.Network")
    strLocalDrive = WScript.Arguments.Item(0)
    strRemoteShare = WScript.Arguments.Item(1)
    strPer = "FALSE"
    strUsr = WScript.Arguments.Item(2)
    strPas = WScript.Arguments.Item(3)
    objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
    my problem is i can easily accomplish this by using .batch file but i dont want to reveal my username and password
    i just want to know is there any way thru which i can somehow link java program with dos command and execute vbs file
    from my java program.
    the code that i have got is not working properly or has to be modified to work.
              String os = System.getProperty("os.name").toLowerCase();
         if (os.indexOf("windows") != -1)
              String[] command = new String[]{"cmd.exe", "/c","cscript","c:\\map.vbs", '"'+strDrive+'"','"'+strPath+'"',"<username>" ,"<password>"};
              Runtime.getRuntime().exec(command);
    Kindly help me as this is very urgent.

    prompt for the login, the password, and the new share name, and store them in variables, then, you can do something like:
    Runtime.getRuntime().exec("net use " + sharenameVar + " \\\\HOST\\share /user:HOST\\" + userVar + " \"" + passwordVar + "\"");with the following values:
    HOST: PC10
    user : toto
    pass : a password
    sharename: I:
    it will result in :
    net use I: \\PC10\share /user:PC10\toto "a password"
    this will map the new share with the given credentials ; there is no need to add some complexity by using a vbscript to do that

  • How to execute bapi through ep?

    hi!
         I want to display PO on EP, for which i created one model for BAPI_PO_GETDETAIL. Then I bind import elements of BAPI with inputfield.
    Please let me know what has to be done after this to display the content on ep on click of button(any code has to be written for this or bapi executes automatically).
    Thanks

    Hi Vijay,
    Please go through this tutorial which demonstrates the use of BAPI with WebDynpro and accessing it via EP.
    here is hte link of the tutorial:
    http://help.sap.com/saphelp_nw04/helpdata/en/c3/76b45d9688e04abe1a1070410ddc1e/content.htm
    Regards,
    Tejas

  • How to execute SQL through OEM GC, using different OS user?

    Hi all,
    I have a relatively simple issue, and I'm hoping there's a simple fix. This is all being done on ONE server - so on this server, I have OEM 11.1.0.1.0, the agent, and several 11.2 databases running. The OEM install is owned by the "oem" OS user, while the databases I'm connecting to are owned by a different OS user "oracle". All normal OEM GC operations are working great, just this one issue I am having.
    Through OEM, I am trying to go in and execute some simple SQL statements against a database. When I do this, I am selecting to "Override Preferred Credentials", and I'm putting in the host and database username/pwds. It all works fine, but only if I specify the OS user that owns the OEM install (oem). If I try to put in the OS user that owns the actual Oracle database install (oracle), then it is failing. It is not giving me any error messages, just a red X under "Execution Status", and when I click on it, it just says "(No results available)". Again, when I change the query so that the host credentials are the "oem" user, then it runs fine.
    I am not sure what I need to do, so that it can run the query, but use a different host login? Any thoughts/ideas?
    Thanks!!
    --Brad                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    It may be that when Grid logs in using the preferred credentials you've specified that the environment is not being set properly. When you log in interactively as this other user (the owner of the Oracle RDBMS binaries) do you need to manually set environment variables such as ORACLE_HOME or PATH in order to run sqlplus ? Or are they set in the user's .profile? I am assuming that this is a Linux / UNIX system and not Windows.

  • How to get values through JavaScript

    Hi,
    I have a report region, in this report one column is Select List having values 1,2,3,4,5 & other columns are text fields.
    I want if user selects 1 from select list then next column of report should get disabled.
    Any help would be really appritiated.
    Thanks,

    onchange="javascript:setvalues(this,'here your text filed name')";Note: text field name like f01..
    put the above code in report column attributes -->
    select list column--> Tabular form Element --> element attributes
    Then
    <script type="text/javascript">
    function setvalues(filter,textboxname)
    var s = filter.id; ----> this is for your report id taken
    var item = s.substring(3,8); --> common id
    var field3 = textboxname + item; ---> now it will give your text box name its look like f05_0001
    alert(filed3);
    var a = filter.value; ----> it will give your select list value.
    alert(a);
    }take the alert message values.
    put the code in page attributes --> HTML Header.
    check this first ...
    send your text box id. it will look like ex: f05_0001
    Cheers,
    Shan

  • How to change label in charts in CRM 2013

    I want to change x-axis and y-axis label in chart. Please guide me how to change label in chart.

    http://mscrmninja.tumblr.com/post/15553130574/changing-chart-axis-titles-in-crm-2011
    My blog: www.crmanswers.net -
    Rockstar 365 Profile

  • Filter Subgrid with Javascript - MS CRM 2013

    Hi,
    I want to filter a subgrid.
    My code :
    function FilterCasesSubgrid() {
    var CasesSubgrid =Xrm.Page.getControl("lots_associes");
    if(CasesSubgrid==null){
    setTimeout(function () { FilterCasesSubgrid(); }, 2000); //if the grid hasn’t loaded run this again when it has
    return;
    var fetchXml ="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
    "<entity name='new_lot'>"+
    "<attribute name='new_name' />"+
    "<attribute name='new_nomduprogramme' />"+
    "<attribute name='new_villelookup' />"+
    "<attribute name='new_loyertotal' />"+
    "<order attribute='title' descending='false' />"+
    "<filter type='and'>"+
    "<condition attribute='new_name' operator='eq' value='004' />"+
    "</filter>"+
    "</entity>"+
    "</fetch>";
    //Here i set the fetchxml directly to subgrid
    alert("1");
    CasesSubgrid .control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
    alert("2");
    CasesSubgrid .control.Refresh(); //refresh the sub grid using the new fetch xml
    with that I only have the first alert who says '1'. The last alert isn't displayed and the subgrid isn't modified.
    Do you have any idea?

    hey even i am facing the same issue..apparently this works only for Internet Explorer and not chrome or firefox...
    i even  tried with  Xrm.Page.ui.controls.get() and Xrm.Page.getControl() both didn't work for me
    //var SubscriptionGrid = Xrm.Page.ui.controls.get("Subscriptions");
    //var InvoiceGrid = Xrm.Page.getControl("Invoices");
    Does anybody have any suggestions for it.

  • On demand workflow javascript crm 2013

    Hi
    I am struggling to make the on-demand workflow working in JavaScript in CRM 2013. Can you please help ?
    it was working fine in CRM 2011.
    Thanks for your help.

    Hi,
       There is no change. However here is the code snippet
    function RunWorkflow() {
    var _return = window.confirm('Are you want to execute workflow.');
    if (_return) {
    var url = Xrm.Page.context.getServerUrl();
    var entityId = Xrm.Page.data.entity.getId();
    var workflowId = '541B45C9-3F88-4448-9690-2D4A365C3172';
    var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
    url = url + OrgServicePath;
    var request;
    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/\">" + entityId + "</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", url, true)
    // 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", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
    req.onreadystatechange = function () { assignResponse(req); };
    req.send(request);
    function assignResponse(req) {
    if (req.readyState == 4) {
    if (req.status == 200) {
    alert('successfully executed the workflow');
    Relevant links:
    http://www.mscrmconsultant.com/2013/03/execute-workflow-using-javascript-in.html
    https://community.dynamics.com/crm/f/117/t/143712.aspx
    Hope this helps.
    Minal Dahiya
    blog : http://minaldahiya.blogspot.com.au/
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

  • MS CRM 2013 : F5/refresh the page and creates new record

    Hi All,
    Refresh the saved form again open as new record.
    I have opened the phone call form from member entity, phone call opened has a new window.
    I have entered data and save the form and it saved the data.If same form I refresh then it creates as a new form instead of exit form.
    I think this issue was resolved in Rollup 5 in MS CRM 2011.
    Please let me know how to solve this issue in MS CRM 2013.
    Thanks,
    Bhaskar

    Hi All,
    i´ve got the same issue.
    Any solutions?
    Greetings
    Sebe

Maybe you are looking for

  • Cisco ASA 5505 not able to access flash

    Hi All: I have searched and searched all over the net for an answer to this question and have decided to just post it. I have a 5505 that was given to me by my job to use for working on my CCNA Sec. cert and did the following: I plugged it in and boo

  • How do i sync multiple ipads at the same time?

    I am a high school principal and I have just received 80 new mini iPads.  I know that there is a much better way to sync them than doing all 80 of them individually.

  • I want to combine 9 images into one so I can get them printed on a card any help or do I need an inexpensive app?

    I would like to combine 9 images into one so that I can print them on a card. Can I do this in i-photo or do I need an inexpensive app?

  • 0Record Mode

    Hi Guys,        I have created one generic data source with numeric pointer for delta. I am feeding data into ODS object. I want to know what to do about 0recordmode info object. I think i need to write a small abap code in update rules. Can anyone t

  • Button Fonts Help!!!!!!!!!!!!!!!!!!!

    I would like to seek expert advice on how to change Fonts type which appear on the button created using Java j2sdk1.4.1_04. I would like to change some fonts type by defaults to perhaps "Wingdings 2" etc... Can any one advise how to? Given ----------