Blog, Development

Xrm.Navigation.navigateTo – gotchas, tricks and limitations

Here are ways that were used by developers to show Modal Dialogs:

  1. Xrm.Internal.openDialog
  2. Alert.js
  3. Custom Dialogs that used different frameworks like jQuery UI Dialog or similar

But the main and common issue of options available was that those approaches can’t be considered as supported.

And it stayed the same for years until Microsoft introduced Xrm.Navigation.navigateTo method.

So what’s new here?

Here is the code that can be used to open a modal dialog:

So far so good. When this code is called following dialog window is shown:

First thing that I’m not comfortable with is the fact that the header of the dialog just uses the name of the webresource that’s not friendly at all. I found only unsupported way to set it so far. Following code added to the onload script of the dialog sets the header’s label:

Once code is added, dialog starts to look friendlier:

Next part is extraction of parameters passed to the webresource. Firstly I tried getQueryStringParameters of GlobalContext in two combinations – GetGlobalContext().getQueryStringParameters and Xrm.Utility.GetGlobalContext().getQueryStringParameters and both calls did not bring the expected result. So… the last resort is explicit parsing of the url. Following code can be used for parsing:

Now let’s make this dialog look closer to standard dialogs and add “OK”/”Cancel” buttons to it. There are multiple ways of doing this. I decided to use “Office UI Fabric” for this purpose. Here is the code of the dialog page:

Here is how it looks like after modifications:

Unfortunately there is only unsupported way to close dialog at the moment. Following code can be used to close it:

Another limitation that was not resolved yet is how to return some data back to the code that called the dialog.


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.