Here is an illustration of application messaging in Infor Smart Office to send, broadcast, and receive messages, and process responses between applications in Smart Office, whether in scripts, Mashups, or other entities.
Documentation
The Infor Smart Office SDK Developer’s Guide has Chapter 19 Application messages, and the Smart Office SDK help file has the API reference for Mango.UI.Services.Messages.ApplicationMessageService:
Note: For more information on the Smart Office SDK refer to my previous post.
Scripts
Here are some examples of sending, broadcasting and receiving messages, and processing responses in Smart Office scripts; the other party in the communication can be another script, a Mashup or another entity in Smart Office.
To send a message and process the response:
import Mango.UI.Services.Messages; package MForms.JScript { class ApplicationA { public function Init(element: Object, args: Object, controller : Object, debug : Object) { // send message var message: ApplicationMessage = new ApplicationMessage(); message.Sender = "ApplicationA"; message.Recipient = "ApplicationB"; message.Parameter = "Hello World"; var response: ApplicationMessageResponse = ApplicationMessageService.Current.SendMessage(message); // process response response.MessageStatus; response.Result; } } }
To receive a message and return a response:
import Mango.UI.Services.Messages; package MForms.JScript { class ApplicationB { public function Init(element: Object, args: Object, controller : Object, debug : Object) { ApplicationMessageService.Current.AddRecipient("ApplicationB", OnMessage); } function OnMessage(message: ApplicationMessage): ApplicationMessageResponse { message.Sender; message.Recipient; message.Parameter; var response: ApplicationMessageResponse = new ApplicationMessageResponse(); response.MessageStatus = MessageStatus.OK; response.Result = "Bonjour"; return response; } } }
To broadcast a message (there is no response):
import Mango.UI.Services.Messages; package MForms.JScript { class ApplicationC { public function Init(element: Object, args: Object, controller : Object, debug : Object) { var broadcastMessage: ApplicationMessage = new ApplicationMessage(); broadcastMessage.Sender = "ApplicationC"; broadcastMessage.Recipient = "GroupX"; broadcastMessage.Parameter = "HELLO WRRRLD!!!!!!"; ApplicationMessageService.Current.SendBroadcastMessage(broadcastMessage); } } }
To receive a broadcasted message (there is no response):
import Mango.UI.Services.Messages; package MForms.JScript { class ApplicationD { public function Init(element: Object, args: Object, controller : Object, debug : Object) { ApplicationMessageService.Current.AddBroadcastRecipient("GroupX", OnBroadcastMessage); } function OnBroadcastMessage(message: ApplicationMessage) { message.Sender; message.Recipient; message.Parameter; } } }
Mashups
Here are some examples of sending, broadcasting and receiving messages in Smart Office Mashups (there are no responses); the other party in the communication can be another Mashup, a script or another entity in Smart Office.
To send a message (there is no response):
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="clr-namespace:Mango.UI.Controls;assembly=Mango.UI" xmlns:mashup="clr-namespace:Mango.UI.Services.Mashup;assembly=Mango.UI"> <Button Name="BtnMessage" Content="Send" Width="150" /> <mashup:ApplicationMessageControl Name="test"> <mashup:ApplicationMessageControl.Events> <mashup:Events> <mashup:Event SourceName="BtnMessage" SourceEventName="Click" TargetEventName="Send" Debug="True"> <mashup:Parameter TargetKey="Sender" Value="MashupE" /> <mashup:Parameter TargetKey="Recipient" Value="MashupF" /> <mashup:Parameter TargetKey="Parameter" Value="Hello World" /> </mashup:Event> </mashup:Events> </mashup:ApplicationMessageControl.Events> </mashup:ApplicationMessageControl> </Grid>
To receive a message (there is no response):
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="clr-namespace:Mango.UI.Controls;assembly=Mango.UI" xmlns:mashup="clr-namespace:Mango.UI.Services.Mashup;assembly=Mango.UI"> <mashup:ApplicationMessageControl Name="test" Recipient="MashupF"> <mashup:ApplicationMessageControl.Events> <mashup:Events> <mashup:Event SourceEventName="Received" Debug="True"> <mashup:Parameter SourceKey="Sender" /> <mashup:Parameter SourceKey="Recipient" /> <mashup:Parameter SourceKey="Parameter" /> </mashup:Event> </mashup:Events> </mashup:ApplicationMessageControl.Events> </mashup:ApplicationMessageControl> </Grid>
To broadcast a message:
<mashup:Event...TargetEventName="Broadcast">
To receive a broadcasted message:
<mashup:ApplicationMessageControl...BroadcastRecipient="Everyone">
Illustration
Here is an illustration of messages going in all directions between scripts and Mashups:
More
The ApplicationMessageService API has more methods and properties available:
- You can send multiple parameters and multiple result values with Dictionary<string, Object>.
- You can return different MessageStatus values depending on your needs, for example OK, Failed or InvalidMessage.
- You can send a message asynchronously to not block the UI; but there is no response.
- You should verify if the recipient already exists before adding a message handler; otherwise you will get the exception “A recipient with the key has already been added.”
- You can remove recipients.
Refer to the SDK documentation for more information.
That’s it. Please like, comment, share, follow, contribute.