Question


Zions Bancorporation
US
Last activity: 27 Mar 2025 14:31 EDT
script events
I have c# code in a DLL that is connecting to the Genesys cloud platform. How do I set up custom events in my Pega script so that I can respond to events occurring in my c# code?
public Class
{
public delegate void OnNotificationHandler();
public event OnNotificationHandler OnNotification;
}
public Constructor()
{
[API].OnNotification += Event1;
[API].OnSubscribed += Event2;
[API].OnUnSubscribed += Event3;
[API].OnNotificationStarted += Event4;
[API].OnDisconnect += Event5;
}
public void Event1()
{
OnNotification?.Invoke();
}
-
Reply
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!


Pegasystems Inc.
US
@ScottC37 You might have to tweak things, but I did get this script working mostly. It seems to fire the event multiple times, but I believe that is because I am not unsubscribing from it afterwards. You'd need to instantiate your object from Genesys inside your script. You'd also need to be running the script in order for the event to be caught as far as I know.
#region Usings
using System; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Reflection; using System.Web; using System.Windows.Forms; using System.Xml;
using ScriptLogger = Pega.Core.Script.ScriptLogger;
#endregion
public class Script { #region Logging examples
// ScriptLogger.LogDebug("test"); // ScriptLogger.LogInformation("test"); // ScriptLogger.LogWarning("test"); // ScriptLogger.LogError("test"); // ScriptLogger.LogException(exception); // ScriptLogger.LogException(exception, "test");
#endregion public delegate void MyEventHandler(object sender, EventArgs e);
@ScottC37 You might have to tweak things, but I did get this script working mostly. It seems to fire the event multiple times, but I believe that is because I am not unsubscribing from it afterwards. You'd need to instantiate your object from Genesys inside your script. You'd also need to be running the script in order for the event to be caught as far as I know.
#region Usings
using System; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Reflection; using System.Web; using System.Windows.Forms; using System.Xml;
using ScriptLogger = Pega.Core.Script.ScriptLogger;
#endregion
public class Script { #region Logging examples
// ScriptLogger.LogDebug("test"); // ScriptLogger.LogInformation("test"); // ScriptLogger.LogWarning("test"); // ScriptLogger.LogError("test"); // ScriptLogger.LogException(exception); // ScriptLogger.LogException(exception, "test");
#endregion public delegate void MyEventHandler(object sender, EventArgs e);
#region Methods // Define the event based on the delegate public event MyEventHandler MyEvent;
// Method that raises the event public void TriggerEvent() { EventSubscriber(); OnMyEvent(EventArgs.Empty); }
// Protected virtual method to allow derived classes to override the event invocation behavior protected virtual void OnMyEvent(EventArgs e) { MyEvent?.Invoke(this, e); } public void EventSubscriber() { this.MyEvent += OnMyEvent; }
// Event handler method private void OnMyEvent(object sender, EventArgs e) { MessageBox.Show("The event has been triggered!", "Event Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); } #endregion }


Zions Bancorporation
US
Do I need to add the method 'add_MyEvent' to the automation and if so, what do I connect to the value parameter?


Pegasystems Inc.
US
@ScottC37 In my automation, I called the TriggerEvent method. When I called that, the event was triggered in the script and it was responded to by the OnMyEvent handler.


Zions Bancorporation
US


Zions Bancorporation
US


Pegasystems Inc.
US
@ScottC37Are you instantiating the component from the DLL inside your script? I believe it would at least need to have done that to be able to subscribe to the events.