Question

PopUp and RefreshPage - PostMessage

Hello!

On a page, I want to be able to create a pop-up after a certain action, and also, after completing another separate action, to refresh the page. I have 2 business processes, which post the messages using Script Tasks

First Business process:
var userConnection = Get("UserConnection");
Terrasoft.Configuration.MsgChannelUtilities.PostMessage(userConnection,"PopupReturnedMailSent", "Mail has been sent to client!");
return true;

Second Business process:
var userConnection = Get("UserConnection");
Terrasoft.Configuration.MsgChannelUtilities.PostMessage(userConnection,"RefreshPage","");
return true;

In my client module, I wrote the following code:
init: function() {
    this.callParent(arguments);

    Terrasoft.ServerChannel.on(Terrasoft.EventName.ON_MESSAGE, this.onServerMessageReceived, this);
    this.subscribeForWebsocketEvents();
},

onServerMessageReceived: function(scope, message) {
    var sender = message && message.Header.Sender;

    if (sender === "PopupReturnedFlowApiError") {
        Terrasoft.showInformation("An error occured. Please retry."); //Opportunity Inactive
    }

    if (sender === "RefreshPage") {
        this.reloadEntity();
    }
},

destroy: function() {
    Terrasoft.ServerChannel.un(Terrasoft.EventName.ON_MESSAGE, this.onServerMessageReceived, this);
    this.unsubscribeForWebsocketEvents(); 
    
    this.callParent(arguments);
},

subscribeForWebsocketEvents: function() {                 
    this.Terrasoft.ServerChannel.on(this.Terrasoft.EventName.ON_MESSAGE,                     
                                    this.onWebsocketMessage, this);             
},             
unsubscribeForWebsocketEvents: function() {                 
    this.Terrasoft.ServerChannel.un(this.Terrasoft.EventName.ON_MESSAGE,                     
                                    this.onWebsocketMessage, this);             
}

I get the following error in the console:


The functionality is still working, but I get these errors in console. I noticed that the Refresh sender doesn't need subscribeForWebsocketEvents and unsubscribeForWebsocketEvents functions, but I think these are needed for the pop-up sender.
 

Like 0

Like

2 comments

In the subscribeForWebsocketEvents and unSubscribeForWebsocketEvents you're referencing a function named onWebsocketMessage but your actual function is named onServerMessageReceived.

That is the cause of the error. Update those functions to use onServerMessageReceived.

Ryan

Good morning Ryan Farley,

 

Thank you, I thought onWebsocketMessage is a core function that must be called for pop-up, but it works without it, as you said :)

 

Final code:

init: function() {
	this.callParent(arguments);
	// register our function to receive messages
	Terrasoft.ServerChannel.on(Terrasoft.EventName.ON_MESSAGE, this.onServerMessageReceived, this);
},
 
onServerMessageReceived: function(scope, message) {
	var sender = message && message.Header.Sender;
 
	if (sender === "PopupReturnedFlowApiError") {
		Terrasoft.showInformation("An error occured. Please retry.");
	}
 
	if (sender === "RefreshPage") {
		this.reloadEntity();
	}
},
 
destroy: function() {
	// unregister so we no longer get messages
	Terrasoft.ServerChannel.un(Terrasoft.EventName.ON_MESSAGE, this.onServerMessageReceived, this);
	this.callParent(arguments);
},
Show all comments