Gets or sets the name of a macro or script to be run when a custom event occurs.
object.OnCustomEvent = [string]
Where object is an object expression that evaluates to one of the controls in the Applies To list, and string is a string expression specifying the script or macro to run when a custom event is triggered.
Newlook Smartclient only.
This property is typically set during the creation of a session (by including the OnCustomEvent parameter in the Options argument of the Add method - see example below).
It is used to specify the macro or script to be run when a custom event is triggered in the session via the TriggerCustomEvent method.
This property (and the associated method used to trigger a custom event) are useful if you want to provide callbacks between sessions. For example, you may wish to notify another session that a particular action has finished or that an error has occurred.
The following example creates a new session, assigning the OnCustomEvent in the process. This specifies that the script "OnHelperCallback" should run whenever a custom event is triggered in the new session:
var helperSession1 = Session.Add("Helper", {
"StartupType": "Logic",
"Startup": "HelperStartup",
//Assign "OnHelperCallback" to the 'Session.OnCustomEvent' property
"OnCustomEvent": "Events.OnHelperCallback"
});
These examples show two different TriggerCustomEvent calls:
function NameLookup()
{
var memberID = App.GetValue("MemberID");
var result = Sessions.Helper.App.PlayTransaction("GetCustomerName", "CustomerNumber=" + memberID);
if (result != "")
{
// Trigger an event to notify the user that the lookup has completed
Sessions.Helper.TriggerCustomEvent("Lookup Success", "Customer name retrieved.");
}
}
function OnFirstReceive()
{
// Trigger an event to notify the startup session that the helper session has started.
ThisSession.TriggerCustomEvent("SessionStatus", "Started");
}
The following is the event callback inside the script 'Events':
function OnHelperCallback(args)
{
switch(args.EventName)
{
case "Lookup Success":
// Notify the user that the look up has completed successfully
Sessions.Session1.App.MsgBox(args.EventValue,args.EventName);
break;
case "SessionStatus":
if (args.SessionName == "Helper")
{
//Set a Newlook variable to monitor session status
Sessions.Session1.App.SetValue("Helper", args.EventValue);
break;
}
}
}
© 2004-2021 looksoftware. All rights reserved.