I’m starting to look at developing custom extensions for my workplace.
I have a project where I need to play a sound when an error occurs in a 3rd party extension.
The problem I am facing is that I would like to trigger the sound after a certain event happens.
I subscribed to the correct event using the following code
codeunit 60102 "AudioFeedback"
[EventSubscriber(ObjectType::Codeunit, Codeunit::"CodeUnitName", 'ActualEvent', '', true, true)]
By moving my procedure into an Event, I no longer have access to the page variable called CurrPage.
I understand why this doesn’t work but I can’t seem to find a way around it.
Can I either pass the CurrPage object to my procedure or should my procedure dispatch a new event that is captured by my page and then executes the code.
My apologies if I’m not using the correct terms. I know many languages but AL is bran new to me.
It sounds like you’re on the right track with your understanding of events and procedures in AL. When you move your procedure into an event subscriber, you lose access to the CurrPage object because it is not available in the event context.
One solution would be to pass the CurrPage object as a parameter to your procedure. You can do this by adding a parameter to your procedure definition, like this:
Then, when you subscribe to the event, you can pass the CurrPage object as a parameter, like this:
[EventSubscriber(ObjectType::Codeunit, Codeunit::“CodeUnitName”, ‘ActualEvent’, ‘’, true, true)]
Alternatively, you could have your event subscriber dispatch a new event that is captured by your page and then executes the code. To do this, you would need to define a new event in your controlAddIn and subscribe to it in your page extension. When the event is fired in the event subscriber, it would raise the new event, which would then be captured by your page extension and execute the code to play the sound.
I hope this helps! Let us know if you have any further questions