In Dynamics 365 there has been a serious re-arrangement of all the namespaces and methods available for client-side scripting. If you are not aware of that already, please take some time to digest the following article:
There are many changes, but today I would like to focus on new namespace: Xrm.Navigation, which, as the name states, contains methods used for moving around the system and opening some resources. This functionality was previously inside Xrm.Utility namespace. Methods which we can use are the following:
Let’s look closely on each of them.
Looks much better right? The function can be called the following way:
Xrm.Navigation.openAlertDialog(alertStrings,alertOptions).then( closeCallback, errorCallback);
alertStrings and alertOptions are JSON objects specifying texts shown on the dialog and height/width of the dialog.
Example usage can look like that:
The equivalent of the deprecated Xrm.Utility.confirmDialog. This method looks now like that:
Xrm.Navigation.openConfirmDialog(confirmStrings,confirmOptions).then( successCallback, errorCallback);
Like before, confirmStrings and confirmOptions are JSON objects with some configuration. Have a look at the example:
There was no equivalent of this one before 9.0. This can simply show the error message which we are used to, but with all options (including the contents of the error log) specified by the developer. Again the method looks pretty straightforward:
Xrm.Navigation.openErrorDialog(errorOptions).then( successCallback, errorCallback);
Look at the example to check what errorOptions object consists of:
This is also something new. This function allows us to open a file for example from an annotation in a supported way. Function looks like that:
file is a JSON object specifying the file name and contents, while openFileOptions can have value of 1 to open file, and 2 to save file (behaviour of course depends on browser settings, most likely both these options will show file save confirmation dialog from the browser). Example usage:
It replaces the old Xrm.Utility.openEntityForm and Xrm.Utility.openQuickCreate functions. Function is quite generic, the usage looks like that:
Xrm.Navigation.openForm(entityFormOptions,formParameters).then( successCallback, errorCallback);
To open account entity with some field prepopulation you can go with:
Result (see that the name has been populated):
There are many, many options here, including createFromEntity which will designate a record to prepopulate fields based on the mapping, opening in new window or specifying business process flow that should be displayed on the form. Really go through the documentation on this one.
Opens specified URL and also there was no relevant function before 9.0 (so basic functionality, no comment…). Function is really simple:
The old version (Xrm.Utility.openWebResource) was usually not very useful as we had no control on how it is opened and it was always a new window. The new version gives us possibility to specify if it should be new window or not but still it lacks the most important feature – to show as a dialog overlaying the current page. As I checked already it almost as useless as the old one, unfortunately The current version can be called the following way: