The other day 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 thanks to 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, as I do, don´t worry, all you need is 8 lines of code. Save the 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 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:

Hope you find it useful.

Creating Sound Alerts In Business Central

Post navigation


One thought on “Creating Sound Alerts In Business Central

Leave a Reply

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

WordPress Cookie Plugin by Real Cookie Banner