Alert.js – a nice little library you can use to display custom popup dialogs in Dynamics

By | September 19, 2017

 

Did you ever want to display a “loading” indicator in Dynamics? Like this one below?

alert_load

For example, if you had a ribbon button that would be calling some kind of lengthy javascript, this kind of indicator would allow you to keep the users informed that Dynamics is still working on whatever it is that button is supposed to do.

That’s just one of the functions in the alert.js, though. There are others, but it’s all about displaying popup notifications in a user-friendly way.

You can download Alert.js solution for Dynamics from github:

https://github.com/PaulNieuwelaar/alertjs

And you can find complete documentation here:

https://github.com/PaulNieuwelaar/alertjs/wiki/Documentation

However, every now and then a question comes up in the Dynamics Community Forum where somebody would ask if alert.js is supported or not.

Paul Nieuwelaar (the author of Alert.js) wrote this:

While technically unsupported, this code is 100% contained within the solution, and doesn’t depend on anything CRM related, so it’s unlikely this will break with CRM updates.

It’s right there, on the alert.js github page.

But that’s what I wanted to elaborate on a bit more in this blog post.

In the Dynamics world, unsupported (when applied to the javascript customizations) means that the javascript is accessing DOM directly. That’s all about using the methods such as getElementById for example.

The problem with these methods is that you never know if they are going to work in the future versions of Dynamics since Microsoft gives no guarantee that there will be no changes in the underlying DOM model. All those html element id-s can change or even disappear, so, in that sense, this kind of scripts are not guaranteed to work after the upgrade.

However, in case with alert.js, it’s not accessing any of the Dynamics HTML controls directly. Probably the one and only “violation” you will notice in that alert.js javascript web resource is this:

Alert.$(“body”).append(alertJsHtml);

This is where an additional HTML element(containing some other elements) is added to the body of the document. The rest of alert.js will be using that dynamically created HTML to display the popups, to set the titles of those popups, etc.

The important part is: since alert.js is creating that HTML, it knows the structure of that html. Which means that, technically, alert.js script is not supposed to break anything even after Dynamics is updated.

Does it make it a supported customization? I would probably say so.. although, there is one scenario where it might break something.

It does not rely on the id-s or names of the Dynamics controls, it’s not trying to manipulate any of the default HTML. However, it’s adding its own HTML to the “body” of the document. Technically, if it ever happens that Dynamics internal javascripts do need HTML elements to be added in a specific order, this is where those scripts may break because of the alert.js. Even though alert.js itself is, probably, going to keep working.

In that sense, it’s probably correct to say that alert.js is, technically, unsupported. But, it seems, the likelihood of alert.js breaking something in Dynamics is very low, and those additional usability features it can bring to Dynamics may well be worth taking a bit of a risk:

image image

image

image

2 thoughts on “Alert.js – a nice little library you can use to display custom popup dialogs in Dynamics

  1. Paul Nieuwelaar

    Great article, couldn’t have said it better myself 🙂

    I’d also like to add that even if there are issues in future versions of CRM (probably most likely due to CRM’s CSS interfering with Alert.js), this project will continually be receiving updates and improvements as new versions of CRM are released. It’s also all open source so if something does break and it doesn’t get fixed right away, someone in the community may take on the challenge to fix it, and then we can merge their changes with Master.

    Reply

Leave a Reply

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