Blogs

Microsoft Dynamics 365 v9.0 – Xrm.Navigation Namespace

, January 18, 20186564 Views

The Xrm.Navigation Namespace is a new namespace, a new feature of Dynamics 365 V9.

This namespace consists of previously known functions such as:-
openAlertDialog, openConfirmDialog, openWebResource, & openForm

And it is also having two new functions:-
openErrorDialog & openUrl

Here in this blog, I will explain you how to use the openErrorDialog & openUrl functions of the Xrm.Navigation Namespace.

Below is the JavaScript code, where, when the user enters a special character in the Name field, an error pop-up will be opened and if the user enters a valid string as Name, then a URL will be opened in a new window.

// JavaScript source code
function xrmNavigationFunctions() {
    var errorOptions = {
        details: "The name is having special character in it. Please enter another name.",
        message: "Error"
        // errorCode :  The error code. 
        // If you just set errorCode, the message for the error code is automatically 
        // retrieved from the server and displayed in the error dialog. 
        // If you specify an invalid errorCode value, an error dialog with a default error message is displayed.
    };
    var openUrlOptions = {
        height: 800,
        width: 800
    };
    var sportsName = Xrm.Page.getAttribute("new_name").getValue();
    var specialCharacters = "@.~`!#$%^&*+=-[]\\\';,/{}|\":<>?";
    var isValidName = true;

    for (var i = 0; i < sportsName.length; i++) {
        if (specialCharacters.indexOf(sportsName.charAt(i)) != -1) {
            isValidName = false;
            Xrm.Navigation.openErrorDialog(errorOptions).then(
                function () {
                    Xrm.Page.getAttribute("new_name").setValue("");
                },
                function () {
                    // Something went wrong
                });
        }
    }

    if (isValidName == true) {
        Xrm.Navigation.openUrl("https://en.wikipedia.org/wiki/Sport/", openUrlOptions)
    }
}

Here, the errorOptions is an object that defines all the options for the openErrorDialog function.

Note:- You must either set the errorCode or message attribute for the openErrorDialog function. Otherwise, an error will be thrown.

When the user enters a special character in the Name field, an error pop-up will be opened as follows:-

When the user clicks on the OK button, he/she will see that the Name field has become blank (as per our JavaScript code)

And, if the user clicks on the Download Log File button. A file will be downloaded, open the downloaded file. He/she will see in it, the message specified in the details attribute of the errorOptions object.

In this way you can open an error pop-up using the Xrm.Navigation.openErrorDialog function.

And, the OpenUrlOptions is an object that defines all the options for the openUrl function. Like, the height & width option will set the height and the width of the error pop-up.

If the user enters a valid string in the Name field, then a URL(as specified in JavaScript code) will be opened in a new window.

In this way you can open a URL using the Xrm.Navigation.openUrl function.

I Hope this helps you…

Happy CRMing!!


 

Insert data into Many-to-Many relationship in Dynamics CRM very easily & quickly, using the Drag and drop listbox.
http://www.inkeysolutions.com/what-we-do/dynamicscrmaddons/drag-and-drop-listbox