Programmatically Starting a Process from Client Code in Creatio (formerly bpm’online)

There are a lot of ways that a process can get started, or triggered in bpm’online. Signals on entity events, messages, timers, and manually starting a process. You can also start a process from code. You can even provide values for parameters in the process to set context if needed. This article will look at how to start a process from client-side javascript code.

To do this, we’ll need to add MaskHelper to our AMD modules list of our code. What this means is, in the page code you’re calling this from, you’ll add something like this:

define("AccountPageV2", ["ProcessModuleUtilities"], function(ProcessModuleUtilities) {
    return {
        entitySchemaName: "Account",

        // ... all the rest of the stuff

    };
});

Note the part at the top, you’ll see “ProcessModuleUtilities” (in quotes) in the square brackets and ProcessModuleUtilities (not in quotes) in the function parameters. Looking at require.js or other searches for AMD modules will show you more info on this topic, but basically it is a way for a module to be provided to your code for you to use.

Now that you’ve added that, it’s easy to use.

var config = {
    sysProcessName: "UsrMyCustomProcess",
    parameters: { 
        SomeProcessParam: someValue 
    }
};
ProcessModuleUtilities.executeProcess(config);

That’s it. The process will be started and you’ve passed a contact parameter for it to use as well. Note, the “parameters” part is only necessary if you need to set a process parameter to provide context.

Also, if you need to do something once the process has completed, you can use a callback as well (if you’re using a callback, also include the scope:this in the config as well:

var config = {
    sysProcessName: "UsrMyCustomProcess",
    parameters: { 
        SomeProcessParam: someValue 
    },
    callback: function() {
        this.reloadEntity();
        Terrasoft.showInformation("The process has completed.");
    },
    scope: this
};
ProcessModuleUtilities.executeProcess(config);

Note: If you’re using a callback when starting a process, you are responsible to hide (turn off) the loading mask in the callback. See Showing the Loading or Progress Indicator for more info. In short, add the MaskHelper module, then call MaskHelper.HideBodyMask(); in the callback function.

ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

14 Comments

  1. Hi,

    I am using the callback method. After callback method execution, page keep on loading. Please suggest.

    Thanks

    Reply
    • Hi,
      I have used your method and it is working to call a process, but it seems that it will only do it once until the cache is cleared. Do you know how this can be fixed so it is run every time the page is opened?

    • Heather, I don’t get that same behavior of “it will only do it once until the cache is cleared”. I use this all the time to start processes, often many times, with no need to clear the cache. There must be something else going on. Note, if you’re using a callback function, you must clear the loading indicator yourself:

      See this article for details https://customerfx.com/article/showing-the-loading-or-progress-indicator-in-bpmonline/
      In short, add the MaskHelper module, then call MaskHelper.HideBodyMask(); in the callback function.

  2. Is it possible to pass data back from a process to the client module?

    Reply
  3. Could this method be used to allow the user to select multiple records from the detail, and then call the process on that group of records? With the base functionality when they select multiple records and call the process, it calls it multiple times. Thanks!

    Reply
    • You could get the Ids of all the selected rows, put them all into one string or array and set that as a param in the process to pass them in to a single process, rather than executing a separate one for each selected row.

    • Thanks so much for your response. When I look in the source code for the client module, I don’t see any reference to the business process that is selectable by the user. Where would I find that so I can change what parameter is sent to the process?

    • This method, and code, doesn’t allow for the user to select a process. This is to programmatically start a process from code. If you wanted the user to be able to select a process, you’d have to display a lookup (via code) to allow the user to select, then run the selected process using the code in this article. However, you’d only want to display the processes for selection that you’ve added the param to that can handle the passed in array of Id values – which also means you’ve built logic into the process to know what to do with that array of Id values

    • My ideal situation would be that the users enter a record page which has a detail section with multiple records in it. They select as many of the details records as they’d like. Then they push a process button called “send email” which sends the email addresses from all those selected records to one process where they put together the email.

      Can you tell me how you would tackle this problem? I’m not sure how to access the “selected items” to read through them all.

      Thanks very much

    • To get an array of all the selected Ids in a detail, you’d use the following:

      var selectedIds = this.getSelectedItems();

      Then you could pass that array to a process to do whatever you needed with it – but you’d have to create the process in a way that it would understand what to do with an array of Ids

  4. Hi Ryan,

    Can you elaborate more on the
    var selectedIds = this.getSelectedItems();

    and share a full code to use.

    I managed to do what you mentioned above, but I’m struggling to pass the detail’s selected ids

    Thanks,
    Raz

    Thanks,
    Raz

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!