Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

Execute ControlAddIn Javascript when from Subcribed Event

Posted on by 20

Hi,

Unsure is this is the correct forum to post dev questions. If not, please let me know and I will delete it.

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.

I’m able to create a controlAddIn and trigger the sound via Javascript by clicking on an navigation button using an action.

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)]
    local procedure CallJavascript()
    begin
        Message('Running')
        CurrPage.AudioFeedback.playAudio('positive');
    end;
}

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.

Thank you in advance for any help.

  • Steven F. Profile Picture
    Steven F. 20 on at
    RE: Execute ControlAddIn Javascript when from Subcribed Event

    Hi Yun,

    thanks for the reply. Unfortunately, the default page triggers are not suitable for my needs and I can't seem to bubble the event back to the page or pass it in a function as my technical skills for AL are still in beginner mode.

  • JJMc Profile Picture
    JJMc 288 on at
    RE: Execute ControlAddIn Javascript when from Subcribed Event

    Try to pass the ControlAdding to the Piblication/Suscription as var and you will manage to achieve it

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,171 Super User 2024 Season 2 on at
    RE: Execute ControlAddIn Javascript when from Subcribed Event

    Hi, As far as I know, you cannot access CurrPage in the event of Codeunit, for example, the standard Page.Update([Boolean]) Method cannot be used either.
    I think you can try to use Page Extension, don't use events, it may be possible to use the Trigger of the page.

    https://learn.microsoft.com/en-us/dynamics-nav/page-and-action-triggers

    Hope this helps.

    Thanks.

    ZHU

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,151 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,993 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans