0

I set up a controlAddin and am able to interact with it using by adding an action that I added to the pageextension.

Basically, the controlAddin is a simple javascript code that plays a sound depending on the result of the action.

I would like to change the behavior in order to trigger the sound after an event from a 3rd party extension is propagated. So far, I've been unable to do so as I can't pass a "CurrPage" as a parameter since it's protected.

This is the code that I have but am a complete beginner in AL.

How can the codeunit have access to the controladdin in order to trigger the sound?

PAGEEXTENSION

pageextension 60101 "WmsAudioFeedbackPageExt" extends "DSHIP Package Worksheet"
{

    layout
    {
        addLast(content)
        {
            usercontrol(WmsAudioFeedback; WmsAudioFeedback)
            {
                ApplicationArea = All;
            }
        }
    }
    actions
    {
        addlast(Navigation)
        {
            action("Play Positive Audio")
            {
                ApplicationArea = All;
                Caption = 'Play Positive Audio';

                trigger onAction()
                begin
                    CurrPage.WmsAudioFeedback.playAudio('positive');
                end;
            }
            action("Play Negative Audio")
            {
                ApplicationArea = All;
                Caption = 'Play Negative Audio';

                trigger onAction()
                begin
                    CurrPage.WmsAudioFeedback.playAudio('negative');
                end;
            }
        }
    }
}

CODEUNIT

codeunit 60102 "WmsAudioFeedbackCodeUnit"
{

    SingleInstance = true;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"DSHIP Event Publisher", 'OnAfterScan', '', true, true)]
    local procedure OnAfterScan(scan: Text; docType: Option; docNo: Code[50]; lp: Code[50]; item: Code[50]);
    begin
        //CurrPage.WmsAudioFeedback.playAudio('positive'); ==> ????
    end;    
}
VVV
  • 7,563
  • 3
  • 34
  • 55

1 Answers1

0

Is there any specific reason to use the CurrPage instance? Control addin can be placed on a new custom page, it doesn't have to be in an extension of a specific page. I think something like this should work.

page 60101 "AudioPlayer"
{
    layout
    {
        area(Content)
        {
            usercontrol(WmsAudioFeedback; WmsAudioFeedback)
            {
                ApplicationArea = All;
            }
        }
    }

    procedure PlayPositiveAudio()
    begin
        CurrPage.WmsAudioFeedback.playAudio('positive');
    end;

    procedure PlayNegativeAudio()
    begin
        CurrPage.WmsAudioFeedback.playAudio('negative');
    end;
}

Then this page can be declared as a local variable in the event subscriber and used to call the JavaScript method.

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"DSHIP Event Publisher", 'OnAfterScan', '', true, true)]
    local procedure OnAfterScan(scan: Text; docType: Option; docNo: Code[50]; lp: Code[50]; item: Code[50]);
    var
        AudioPlayer: Page AudioPlayer;
    begin
        AudioPlayer.PlayPositiveAudio();
    end;