Hi All,
In case section,I am calling a process on save inside a popup.
The process is not triggering handleServerChannelMessage on success of it.
The code is below.
save: function() {this.openInputBox();
this.callParent(arguments);},
openInputBox: function(obj) {
var GetAnswerButton = this.Ext.create("Terrasoft.Button", {
returnCode: "GetAnswer",
className: "Terrasoft.Button",
caption: "Get Answer",
style: this.Terrasoft.controls.ButtonEnums.style.GREEN
});
var SkipButton = this.Ext.create("Terrasoft.Button", {
returnCode: "Skip",
className: "Terrasoft.Button",
caption: "Skip",
style: this.Terrasoft.controls.ButtonEnums.style.Blue,
enabled: !obj.SBLCanSkip,
});
var NextButton = this.Ext.create("Terrasoft.Button", {
returnCode: "Next",
className: "Terrasoft.Button",
caption: "Next",
style: this.Terrasoft.controls.ButtonEnums.style.Blue
});
var controls = {
"UsrReference": {
dataValueType: Terrasoft.DataValueType.TEXT,
isRequired: obj.SBLCanSkip,
caption: this.get("UsrQuestion"),
value: {
layout: {
"colSpan": 24,
"rowSpan": 1,
"column": 0,
"row": 1
},
bindTo: "UsrReference",
},
customConfig: {
enabled: false
}
},
};
Terrasoft.utils.inputBox("Call Center Question",
this.openInputBoxHandler,
[GetAnswerButton, SkipButton, NextButton],
this,
controls
);
Terrasoft.each(Terrasoft.MessageBox.controlArray, function(item) {
item.control.bind(this);
}, this);
},
openInputBoxHandler: function(returnCode, controlData) {
if ("GetAnswer" === returnCode) {
var args = {
sysProcessName: "SBLTestMessage",
};
ProcessModuleUtilities.executeProcess(args);
Terrasoft.ServerChannel.on(Terrasoft.EventName.ON_MESSAGE, this.handleServerChannelMessage, this);
}
},
handleServerChannelMessage: function(channel, message) {
var messageSenderName = message && Terrasoft.ServerChannel.getSenderName(message);
if (messageSenderName === "Answer") {
var data=message.Body;
}
},
Like
Hello Akshaya,
Firstly, you should subscribe on ServerChannel and after that execute your process.
The best way how to use WebSocket (please, don't forget to unsubscribe on destroy):
methods: {
init: function() {
this.callParent(arguments);
Terrasoft.ServerChannel.on(Terrasoft.EventName.ON_MESSAGE, this.onMessageReceived, this);
},
onMessageReceived: function(sender, message) {
if (message && message.Header && message.Header.Sender === "MySenderName") {
var result = this.Ext.decode(message.Body);
/// TODO: your code
}
},
destroy: function() {
this.Terrasoft.ServerChannel.un(Terrasoft.EventName.ON_MESSAGE, this.onMessageReceived, this);
this.callParent(arguments);
}
}
Please, let us know in case any further information is required.
Best regards,
Olga.
Olga Avis,
Thanks Olga,
The ON_MESSAGE subscription is already done in process -> script task
MsgChannelUtilities.PostMessage(UserConnection, "Answer","Answer");
But still its not hitting onMessageReceived method ON_MESSAGE , is there anything to be done additionally?
And the same process calling from page is working completely fine in another Creatio instance.
Hello Akshaya,
As was mentioned in the previous post, please, make sure that you have subscribed on ServerChannel and only after that executed your process.
openInputBoxHandler: function(returnCode, controlData) {
if ("GetAnswer" === returnCode) {
Terrasoft.ServerChannel.on(Terrasoft.EventName.ON_MESSAGE, this.onMessageReceived, this);
var args = {
sysProcessName: "UsrTestProcess",
};
ProcessModuleUtilities.executeProcess(args);
}
},
onMessageReceived: function(sender, message) {
if (message && message.Header && message.Header.Sender === "MySenderName") {
var result = this.Ext.decode(message.Body);
/// TODO: your code
}
},
Best regards,
Olga.
Olga Avis,
Ya even after i have subscribed on ServerChannel and only after that executed your process. Still the onMessageReceived is not hitting.
I even tried to subscribe on init() also , still same result.
Akshaya B M,
Please, find an example below:
example
1. Create replacing schema for contactpagev2 and populate that schema with code below .
define("ContactPageV2", ["ProcessModuleUtilities"], function(ProcessModuleUtilities){
return{
entitySchemaName:"Contact",
attributes:{
},
modules:/**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
messages: {
},
businessRules:/**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/,
methods:{
save: function() {
this.openInputBox();
this.callParent(arguments);
},
openInputBox: function(obj) {
var GetAnswerButton = this.Ext.create("Terrasoft.Button", {
returnCode: "GetAnswer",
className: "Terrasoft.Button",
caption: "Get Answer",
style: this.Terrasoft.controls.ButtonEnums.style.GREEN
});
var SkipButton = this.Ext.create("Terrasoft.Button", {
returnCode: "Skip",
className: "Terrasoft.Button",
caption: "Skip",
style: this.Terrasoft.controls.ButtonEnums.style.Blue,
enabled: true,
});
var NextButton = this.Ext.create("Terrasoft.Button", {
returnCode: "Next",
className: "Terrasoft.Button",
caption: "Next",
style: this.Terrasoft.controls.ButtonEnums.style.Blue
});
var controls = {
"UsrReference": {
dataValueType: Terrasoft.DataValueType.TEXT,
isRequired: false,
caption: "TEST",
value: {
layout: {
"colSpan": 24,
"rowSpan": 1,
"column": 0,
"row": 1
},
bindTo: "Name",
},
customConfig: {
enabled: true
}
},
};
Terrasoft.utils.inputBox("Call Center Question",
this.openInputBoxHandler,
[GetAnswerButton, SkipButton, NextButton],
this,
controls
);
Terrasoft.each(Terrasoft.MessageBox.controlArray, function(item) {
item.control.bind(this);
}, this);
},
openInputBoxHandler: function(returnCode, controlData) {
if ("GetAnswer" === returnCode) {
Terrasoft.ServerChannel.on(Terrasoft.EventName.ON_MESSAGE, this.onMessageReceived, this);
var args = {
sysProcessName: "UsrTestProcess",
};
ProcessModuleUtilities.executeProcess(args);
}
},
onMessageReceived: function(sender, message) {
if (message && message.Header && message.Header.Sender === "MySenderName") {
var result = this.Ext.decode(message.Body);
/// TODO: your code
}
},
destroy: function() {
this.Terrasoft.ServerChannel.un(Terrasoft.EventName.ON_MESSAGE, this.onMessageReceived, this);
this.callParent(arguments);
}
},
dataModels:/**SCHEMA_DATA_MODELS*/{}/**SCHEMA_DATA_MODELS*/,
diff:/**SCHEMA_DIFF*/[
]/**SCHEMA_DIFF*/
};
});
2. Create a business process which contains a simple signal and script task
Code of the process: UsrTestProcess
Populate such usings:
Terrasoft.Configuration
Terrasoft.Messaging.Common
Newtonsoft.Json
Populate script task with such code:
string senderName = "MySenderName";
// Example for message
string message = JsonConvert.SerializeObject(new {
Name = "Some name"
});
// For all users
MsgChannelUtilities.PostMessageToAll(senderName, message);
return true;
Best regards,
Olga.