How to Refresh a Page from a Process in Creatio (formerly bpm’online)

In this article I will tell you how to refresh a page from a process in Creatio. It’s pretty common for a process to run on a signal from a record being saved. That process might update fields that you want the user to see right away. To do that you’ll need to refresh the page once the process is complete. From our process we will send a message and then listen for that message on the page. Whenever we get that message it will refresh the page and the user will see any changes right away.

For this example when a contact is saved I need to go get some values from the contact’s account and then put those values in fields on the contact. For this to work I need to refresh the page once the process is done. Without this, the user won’t see the new values until they reopen the contact.

I’ll add a script task as the last task in my process. I’ll add code to this script task that will send a message back to my page.

The code I’ll add to that script task is this

Terrasoft.Configuration.MsgChannelUtilities.PostMessageToAll("FXRefreshContactPage", "");
return true;

When this code calls PostMessageToAll it gives a name of our message. In this case it’s FXRefreshContactPage. You want the name of your message to be unique. This part sends the message, now we have to go edit the page to receive it. Once you start editing the page you’ll want to put in some code that allows the page to receive the message. This is the code that I put in the page.

init: function() {
	this.callParent(arguments);
	// register our onProcessMessageReceived function to get messages from the server
	Terrasoft.ServerChannel.on(Terrasoft.EventName.ON_MESSAGE, this.onProcessMessageReceived, this);
},
onProcessMessageReceived: function(scope, message) {
	var sender = message && message.Header.Sender;
	if (sender === "FXRefreshContactPage") {
		this.reloadEntity();
	}
},
destroy: function() {
	// un-register the function when the page is destroyed so it stops receiving messages
	Terrasoft.ServerChannel.un(Terrasoft.EventName.ON_MESSAGE, this.onProcessMessageReceived, this);
	this.callParent(arguments);
}

First we register to get messages from the server in the init, later, in the page destroy, we’ll unregister the function. When a message is received it will call our function named onProcessMessageReceived (we could name this whatever we want). This code will receive all messages so we have to check that it’s the message that we sent from our process. Once we get our message we call reload entity which reloads all the data on the page. Now the user will be able to see right away any changes that you’ve made to the record in the process.

Note

One thing to keep in mind, that this message is sent from your process to the client for all users. If any users are on a screen listening for the message name, their screen will refresh – not just the user that originally made the change. If you want to refresh the page for the user that made the change, you can include that in the message. To do this the code you add to the script task would look like this:

var payload = new {
    userId = UserConnection.CurrentUser.ContactId
};

Terrasoft.Configuration.MsgChannelUtilities.PostMessageToAll("FXRefreshContactPage", Newtonsoft.Json.JsonConvert.SerializeObject(payload));
return true;

Then, the code on the page that listens for this message would include this to make sure it is a message for the current user only:

onProcessMessageReceived: function(scope, message) {
    var sender = message && message.Header.Sender;
    if (sender === "FXRefreshContactPage") {
        var payload = Ext.decode(message.Body);

        if (payload.userId == Terrasoft.SysValue.CURRENT_USER_CONTACT.value) {
            this.reloadEntity();
        }
    }
}

For more information on sending a message from the server to the client in Creatio, see the article below
Sending a Message from Server-Side C# to Client-Side Javascript in Creatio

6 Comments

  1. Thank you so much for this write up. This helps me greatly in improving user experience.

    Reply
    • Thank you so much! This article really helped me! I like how you explain the idea and functions.

  2. Hi! Is there a way to do the same thing but with a pop-up? I want to add it in a Script Task.

    Thank you!

    Reply
  3. This code doesnt seem to work for me, specifically the reference to “Newtonsoft.Json.JsonConvert.SerializeObject”, as this doesnt seem to be referenced or referenceable by Creatio

    Reply
    • The Newtonsoft library is a core part of Creatio, however, if you’re using the .Net Core version, I am not sure if it is available in that implementation (if that applies to your scenario).

      However, even without the library to serialize the object to JSON, you could still just construct the JSON payload as a string (essentially that is all that the Newtonsoft library is doing in the code in this article, producing a JSON string to send with the message):

      var payload = “{ \”userId\”: \”” + UserConnection.CurrentUser.ContactId + “\” }”;

      Ryan

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!