Dynamically Scaling Alert Dialogue Box in Dynamics 365

Calum Jacobs, 23 June 2021

If you have used Alert Dialogue boxes before in Dynamics 365, you will have noticed that they do not scale dynamically when there is a lot of text. Instead, the out of the box functionality has a default size and displays a scroll bar. This can become messy if there is a case when your Alert Dialogue contains a large amount of text.


To get around this, you need to set the height and width based on the amount of text your Dialogue box will contain. The height and width of a box can be set using the following Xrm.Navigation.openAlertDialog(alertResultStrings, alertOptions); with alert Options containing the height and width, var alertOptions = { height: X, width: Y };.

To make the height and width Dynamic, you need to create variables based on the amount of text in the alert string you are wanting to show (var alertLength = alertString.length;). After playing around with some numbers I found that this works quite well:

var alertHeight = ((alertLength / 50)*14.5) + 200;

var alertWidth = (alertLength / 5.5) + 400;

Putting it all together you get the following:

var alertLength = alertString.length;

if (alertLength > 0) {

var alertHeight = ((alertLength / 50)*14.5) + 200;

var alertWidth = (alertLength / 5.5) + 400;

var alertOptions = { height: alertHeight, width: alertWidth };

var alertResult = { text: alertString, title: "Alert" };

Xrm.Navigation.openAlertDialog(alertResult, alertOptions).then(function () { });



Feel free to play around with the numbers to get the alert height/width for your scenario.

// Tactix campaign Linkedin Tag_April 2022