Enhancement in Microsoft Dynamics 365/Dataverse NavigateTo()

By | June 1, 2021

Introduction

In our last blog, we have seen how we can open a record in a Dialog using NavigateTo(). In this blog, we will see the latest enhancement which Microsoft has added recently.

1. Show Title while displaying custom HTML in a dialog

Earlier when we wanted to open a custom HTML web resource using NavigateTo() there was no provision to provide the ‘Title’ to the ‘NavigateTo()’ dialog and by default, the Title was the Html Web resource name.

Enhancement in Microsoft Dynamics 365

Enhancement in Microsoft Dynamics 365

Because of this reason, if we wanted to give the NavigateTo() dialog any name we needed to change the HTML web resource name. To change the Dialog Title programmatically depending on some condition etc. there was no option but to use unsupported methods.

Enhancement in Microsoft Dynamics 365/Dataverse NavigateTo

Enhancement in Microsoft Dynamics 365/Dataverse NavigateTo

Now we can set the Title Property in the Navigation parameter of the NavigateTo function. Given below is a sample code for the same. To know more about the attributes used, please follow this link.

openCustomHtmlUsingNavigateTo = () => {
                    let functionName: string = "openCustomHtmlUsingNavigateTo;
                    let pageInput = {};
                    let navigationOptions = {};                   
                    try {
                        pageInput = {
                            pageType: "webresource",
//Name of the webresource which we want to open
                            webresourceName : "crbc4_index.html"
                        }
                        navigationOptions = {
                            target: 2,
                            height: { value: 80, unit: "%" },
                            width: { value: 70, unit: "%" },
                            position: 1,
//Provide Title value which you want to display on the NavigateTo window
                             title:"My Page Title 2"                           
                        };
                        Xrm.Navigation.navigateTo(pageInput, navigationOptions).then((success) => {
//Write the code which you want to execute on success
                        }, (error) => {
                                 //Write the code which you want to execute error to handle on exception
                        });
                    } catch (error) {
//Write the code which you want to execute error to handle on exception
                    }
                }
Result – The Title which we provided from our code is set on the NavigateTo window.

Enhancement in Microsoft Dynamics 365

2. Open Record containing Business Process Flow and define BPF which you want to see

Scenario – I want to open an entity record and want to define which Business Process Flow that needs to be visible by default and also wants to expand the current active stage when the form is opened.

In this example I am using Opportunity entity which has two Business Process Flows enabled for it and the default Business Process Flow is Custom BPF named Opportunity BPF.

Enhancement in Microsoft Dynamics 365

In CRM when you create a Business Process Flow, behind the scene a new Entity is created with the name which is given to the Business Process Flow. In this entity, all the Business Process Flow related information is stored. In this example, we would require Business Process Flow entity field values such as BPF Process Id, Business Process Flow instance Id, Active Stage Id that is necessary to open the BPF records. Currently, I am getting the necessary value using Dynamics 365 endpoint API. Similarly, you can retrieve these record values for your projects.

Enhancement in Microsoft Dynamics 365

Given below is the code to achieve our requirement. To know more about the attributes used, please follow this link.

openRecordBPFUsingNavigateTo = () => {
                    let functionName: string = "openRecordBPFUsingNavigateTo";
                    let pageInput = {};
                    let navigationOptions = {};
                    try {
                        pageInput = {
                            pageType: "entityrecord",
                            entityName: "opportunity",
//Opportunity entity record id
                            entityId: = "be0e0283-5bf2-e311-945f-6c3be5a8dd64";,
//BPF Id which we want to open
                            processId: "3e8ebee6-a2bc-4451-9c5f-b146b085413a",
//BPF Process Instance Id
                            processInstanceId: "d3a0d30f-b0b9-eb11-8236-000d3af24bee",
                            isCrossEntityNavigate: true,
//Stage Id which you want to expand when form is opened e.g. In-Progress
                            selectedStageId: "d3ca8878-8d7b-47b9-852d-fcd838790cfd"
                        }
                        navigationOptions = {
                            target: 2,
                            height: { value: 80, unit: "%" },
                            width: { value: 70, unit: "%" },
                            position: 1
                        };
                        // 
                        Xrm.Navigation.navigateTo(pageInput, navigationOptions).then((success) => {
                        //Write the code which you want to execute on success
                        }, (error) => {
                      //Write the code which you want to execute error to handle on exception
                        });
                    } catch (error) {
                        //Write the code which you want to execute error to handle on exception
                    }
                }

Result

As we wanted, when the Opportunity record is Opened using NavigateTo(), the Opportunity Sales Process BPF is visible by default and the current active stage which is Propose is expanded.

Enhancement in Microsoft Dynamics 365

The reference for this blog is taken from the following link – https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-navigation/navigateto

click2export