I was searching on forums and the base app for any built-in method to create some type of sound alert in Business Central. I couldn´t find it so I asked on Twitter if anybody knew how to do it.

Thanks to Gregory for the quick reply. In this post, I will show how to reproduce virtually any sound/whistle in Business Central with controladdins and JavaScript.

JavaScript in Business Central

JavaScript can interact with Business Central and comes in very handy in certain situations. In fact, it might be the only solution for the question I brought up.

For those not familiar with JavaScript, don´t worry, all you need is 8 lines of code. Save this file as ‘.js’:

function CreateSound(Frequency, Duration)
{
    var context = new(window.AudioContext || window.webkitAudioContext)();
    var osc = context.createOscillator();
    osc.type = 'sine';
    osc.frequency.value = Frequency; // Hz
    osc.connect(context.destination);
    osc.start();
    osc.stop(context.currentTime + Duration);
}

You can find more information about this method here:

https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/createOscillator

Simply put, it generates a constant tone by creating a waveform of a specific type, frecuency and duration. You can play with these parameters and create your own custom sound:

Controladdin

The way to call this method with AL is by using a controladdin object like the following:

controladdin "CreateSound"
{
    HorizontalShrink = true;
    HorizontalStretch = true;
    MinimumHeight = 1;
    MinimumWidth = 1;
    RequestedHeight = 1;
    RequestedWidth = 1;
    VerticalShrink = true;
    VerticalStretch = true;
    Scripts = 'scripts/CreateSound.js';

    procedure CreateSound(Frequency: Integer; Duration: Integer);

    event ControlAddInReady();
}

Usercontrol

Finally, we need a usercontrol to invoke the controladdin. Only then, will we be able to call the method ‘CreateSound’:

Video test:

Sound alerts can be helpful when you need the user´s attention. But, in my opinion, they should be used carefully. This implementation can lead to some discussions so feel free to leave your thoughts.

For further understandig of controladdins and their capabilities check another example here:

That´s all. Hope you find it useful.

Creating Sound Alerts In Business Central

Post navigation


2 thoughts on “Creating Sound Alerts In Business Central

  1. Hi,
    thanks for the tutorial. It was very helpful in getting me started.

    Would you have any idea how to trigger the sound on a certain event?
    I’ve been going at this for a while and as a beginner, I’ve yet to find how to do it since the ControlAddin is not accessible in events.
    Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *