Question

Channel message handler not getting triggered in section page

I am calling business process from contact section to run a script task to send a message from server to the page. Based on the message, 

I am trying to display browser notification message. I am facing following issues:

  • Sometimes browser notification message is not being displayed at all or only business process notification ("service is started ") is displayed
  • Often onMessageReceived method is not getting triggered at all despite user task running successfully

kindly help in resolving the issue. Refer below for code

       

//user task code in business process
	var UImessage = JsonConvert.SerializeObject(new
                {
 
                    Message = "Please try again later"
                }
             );
            //intendedUserId is unique identifier parameter sent to business process(current user login)
            var intendedUserId = Get<Guid>("intendedUserId");
 
            IMsgChannel channel = MsgChannelManager.Instance.FindItemByUId(intendedUserId);
            if (channel != null)
            {
                var simpleMessage = new SimpleMessage()
                {
                    Id = intendedUserId,
                    Body = UImessage,
                    Header =
                        {
                         Sender = "BrowserNotification"
                        }
                };
                channel.PostMessage(simpleMessage);
            }
 
 
	return true;
//section page
define("ContactSectionV2", ["DesktopPopupNotification","ProcessModuleUtilities"], function(DesktopPopupNotification,ProcessModuleUtilities) {
	return {
 
		methods: {
			init: function(){
				this.callParent(arguments);
				this.Terrasoft.ServerChannel.on(Terrasoft.EventName.ON_MESSAGE,
				this.onMessageReceived, this);
 
				if (DesktopPopupNotification.getPermissionLevel() !== DesktopPopupNotification.PermissionType.GRANTED) {
					DesktopPopupNotification.requestPermission(); 
 
				}
				//process that runs user task
				this.callCustomProcess();
 
			},
			onMessageReceived: function (sender, message) {
 
				if (message.Header.Sender === "BrowserNotification") 
				{
                  this.console.log("message");
					if (DesktopPopupNotification.getPermissionLevel() !== DesktopPopupNotification.PermissionType.GRANTED) 						{
                      	this.console.log("no permisssion");
                    		return; 
                		}
 
                        var config = {
                            id: 123456,
                            title: "Test notification",
                            body: "This is a test notification",
                            icon: Terrasoft.ImageUrlBuilder.getUrl(this.get("Resources.Images.UsrIcon")),
                            onClick: this.onDesktopNotificationClick,
                            ignorePageVisibility: true,
                            timeout: 5000,
                            scope: this
                        };
					this.console.log("displaying message");
					DesktopPopupNotification.showNotification(config);
				}
 
 
			},
			callCustomProcess: function() {
				var args = {
					// Process name
					sysProcessName: "UsrProcess_05207ff",
					// parameters process
					parameters: {
						UsrLeaveRequestID: parameter
					}
				};
				// run process
				ProcessModuleUtilities.executeProcess(args);
			},
			destroy: function() {
						this.Terrasoft.ServerChannel.un(Terrasoft.EventName.ON_MESSAGE, this.onMessageReceived, this);
						this.callParent(arguments);
			}
        }
	}



 

Like 0

Like

2 comments

Hello,

 

Thank you for the code provided!



The problem here is that starting the process triggers the base _showSuccessfullyRunProcessPopup method that shows the popup that the process was successfully started (ProcessModuleUtilities module in NUI package). And the browser performs a kind of a random choice which popup should be displayed first and how long: the popup about "successful process start" information or your custom one (in some cases I had the "Test notification" popup being displayed first and the "Successfully started" popup then and visa versa).

See that these two notifications are generated simultanously and the browser selected to display "Successfully started" popup first (and the practice showed that the second notification will be never displayed after the first one is displayed).

 

The only way to disable the "Successfully started" popup is to override the _showSuccessfullyRunProcessPopup method in the ProcessModuleUtilities module. As a result custom notification will be shown without any issues.

 

As for displaying the onMessageReceived method - I wasn't able to reproduce that at all, if you have steps to reproduce I can take a look at it as well.

 

Best regards,

Oscar

Oscar Dylan,

Thanks a lot for helping in this issue

Show all comments