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);
}
}
}