Question


Zions Bancorporation
US
Last activity: 1 Apr 2025 12:51 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.


Zions Bancorporation
US
I decided to bypass the script in Pega and call the API directly from the automation. I've created the proxy of the class in the DLL, however, I am getting several errors when I add the events.
Exception from the log file:
Error | 11:07:42.807 AM | 7 | MTA | Exception | | | Could not find an EventLink with PartID = 204, Verbose Message: General Information
Diagnostic Info: Diagnostic.MachineName: Diagnostic.FullName: OpenSpan, Version= Proprietary information hidden, Culture=neutral, PublicKeyToken=f5db91edc02d8c5e Diagnostic.AppDomainName: OpenSpan.Runtime.exe Diagnostic.WindowsIdentity: Diagnostic.ApplicationName: OpenSpan.Runtime
Exception Information
I decided to bypass the script in Pega and call the API directly from the automation. I've created the proxy of the class in the DLL, however, I am getting several errors when I add the events.
Exception from the log file:
Error | 11:07:42.807 AM | 7 | MTA | Exception | | | Could not find an EventLink with PartID = 204, Verbose Message: General Information
Diagnostic Info: Diagnostic.MachineName: Diagnostic.FullName: OpenSpan, Version= Proprietary information hidden, Culture=neutral, PublicKeyToken=f5db91edc02d8c5e Diagnostic.AppDomainName: OpenSpan.Runtime.exe Diagnostic.WindowsIdentity: Diagnostic.ApplicationName: OpenSpan.Runtime
Exception Information
1) Exception Information ********************************************* Exception Type: System.Collections.Generic.KeyNotFoundException Message: "Could not find an EventLink with PartID = 204" Data: IDictionary (System.Collections.ListDictionaryInternal) with 0 items TargetSite: OpenSpan.Automation.EventLink GetEventLink(Int32) HelpLink: NULL Source: "OpenSpan.Automation" HResult: -2146232969
StackTrace Information ********************************************* at OpenSpan.Automation.Automator.GetEventLink(Int32 partID) at OpenSpan.Automation.CatchHost.mAutomator_LinksConnected(Object sender, EventArgs e) at System.EventHandler.Invoke(Object sender, EventArgs e) at OpenSpan.Automation.Automator.ConnectLinks() at OpenSpan.Automation.Automator.BeforeStart() at OpenSpan.Runtime.RuntimeContainerLoader.ExecuteBeforeStart(IDesignComponent dc, Boolean beforeStart) at OpenSpan.Runtime.RuntimeContainerLoader.Start(ISynchronizeInvoke syncObject) Verbose | 11:07:42.811 AM | 1 | STA | Runtime Application | | | WndProc message = 0000C255 Error | 11:07:43.438 AM | 7 | MTA | Exception | | | Could not find an EventLink with PartID = 204, Verbose Message: General Information
Diagnostic Info: Diagnostic.MachineName: Diagnostic.FullName: OpenSpan, Version= Proprietary information hidden, Culture=neutral, PublicKeyToken=f5db91edc02d8c5e Diagnostic.AppDomainName: OpenSpan.Runtime.exe Diagnostic.WindowsIdentity: Diagnostic.ApplicationName: OpenSpan.Runtime
Exception Information
1) Exception Information ********************************************* Exception Type: System.Collections.Generic.KeyNotFoundException Message: "Could not find an EventLink with PartID = 204" Data: IDictionary (System.Collections.ListDictionaryInternal) with 0 items TargetSite: OpenSpan.Automation.EventLink GetEventLink(Int32) HelpLink: NULL Source: "OpenSpan.Automation" HResult: -2146232969
StackTrace Information ********************************************* at OpenSpan.Automation.Automator.GetEventLink(Int32 partID) at OpenSpan.Automation.CatchHost.mAutomator_LinksConnected(Object sender, EventArgs e) at System.EventHandler.Invoke(Object sender, EventArgs e) at OpenSpan.Automation.Automator.ConnectLinks() at OpenSpan.Automation.Automator.BeforeStart() at OpenSpan.Design.DesignComponentCommon.Start() at OpenSpan.Automation.Automator.Start() at CloudTest3.Automation1.Start() in obj\Debug\Automation1.cs:line 2152 at OpenSpan.Runtime.RuntimeContainerLoader.Start(ISynchronizeInvoke syncObject)
Error | 11:07:42.807 AM | 7 | MTA | Exception | | | Could not find an EventLink with PartID = 204, Verbose Message: General Information
Diagnostic Info: Diagnostic.MachineName: Diagnostic.FullName: OpenSpan, Version= Proprietary information hidden, Culture=neutral, PublicKeyToken=f5db91edc02d8c5e Diagnostic.AppDomainName: OpenSpan.Runtime.exe Diagnostic.WindowsIdentity: Diagnostic.ApplicationName: OpenSpan.Runtime
Exception Information
1) Exception Information ********************************************* Exception Type: System.Collections.Generic.KeyNotFoundException Message: "Could not find an EventLink with PartID = 204" Data: IDictionary (System.Collections.ListDictionaryInternal) with 0 items TargetSite: OpenSpan.Automation.EventLink GetEventLink(Int32) HelpLink: NULL Source: "OpenSpan.Automation" HResult: -2146232969
StackTrace Information ********************************************* at OpenSpan.Automation.Automator.GetEventLink(Int32 partID) at OpenSpan.Automation.CatchHost.mAutomator_LinksConnected(Object sender, EventArgs e) at System.EventHandler.Invoke(Object sender, EventArgs e) at OpenSpan.Automation.Automator.ConnectLinks() at OpenSpan.Automation.Automator.BeforeStart() at OpenSpan.Runtime.RuntimeContainerLoader.ExecuteBeforeStart(IDesignComponent dc, Boolean beforeStart) at OpenSpan.Runtime.RuntimeContainerLoader.Start(ISynchronizeInvoke syncObject) Verbose | 11:07:42.811 AM | 1 | STA | Runtime Application | | | WndProc message = 0000C255 Error | 11:07:43.438 AM | 7 | MTA | Exception | | | Could not find an EventLink with PartID = 204, Verbose Message: General Information
Diagnostic Info: Diagnostic.MachineName: Diagnostic.FullName: OpenSpan, Version= Proprietary information hidden, Culture=neutral, PublicKeyToken=f5db91edc02d8c5e Diagnostic.AppDomainName: OpenSpan.Runtime.exe Diagnostic.WindowsIdentity: Diagnostic.ApplicationName: OpenSpan.Runtime
Exception Information
1) Exception Information ********************************************* Exception Type: System.Collections.Generic.KeyNotFoundException Message: "Could not find an EventLink with PartID = 204" Data: IDictionary (System.Collections.ListDictionaryInternal) with 0 items TargetSite: OpenSpan.Automation.EventLink GetEventLink(Int32) HelpLink: NULL Source: "OpenSpan.Automation" HResult: -2146232969
StackTrace Information ********************************************* at OpenSpan.Automation.Automator.GetEventLink(Int32 partID) at OpenSpan.Automation.CatchHost.mAutomator_LinksConnected(Object sender, EventArgs e) at System.EventHandler.Invoke(Object sender, EventArgs e) at OpenSpan.Automation.Automator.ConnectLinks() at OpenSpan.Automation.Automator.BeforeStart() at OpenSpan.Design.DesignComponentCommon.Start() at OpenSpan.Automation.Automator.Start() at CloudTest3.Automation1.Start() in obj\Debug\Automation1.cs:line 2152


Pegasystems Inc.
US
@ScottC37 Without access to the DLL, I can't really speculate. I suspect the first error is really a result of the second one. The missing link error would happen if any object had changed since it was opened in the automation surface. It may just be a case of a missing reference or something like that. You might open a support request to see if they can assist as this might need some hands-on to resolve.