• Home
  • About Us
  • Contact Us
  • Privacy Policy
  • Special Offers
Business Intelligence Info
  • Business Intelligence
    • BI News and Info
    • Big Data
    • Mobile and Cloud
    • Self-Service BI
  • CRM
    • CRM News and Info
    • InfusionSoft
    • Microsoft Dynamics CRM
    • NetSuite
    • OnContact
    • Salesforce
    • Workbooks
  • Data Mining
    • Pentaho
    • Sisense
    • Tableau
    • TIBCO Spotfire
  • Data Warehousing
    • DWH News and Info
    • IBM DB2
    • Microsoft SQL Server
    • Oracle
    • Teradata
  • Predictive Analytics
    • FICO
    • KNIME
    • Mathematica
    • Matlab
    • Minitab
    • RapidMiner
    • Revolution
    • SAP
    • SAS/SPSS
  • Humor

Opening Main Form Dialogs from OOB Grid Events

November 3, 2020   Microsoft Dynamics CRM

Recently with 2020 Wave 2 you may have noticed that breadcrumbs have disappeared from the headers of Model Driven Apps.  This may have left you (as it did me) with a desire to update the way users can navigate through the application.  One of the ways that we can make a change like this is to open records in Dialogs instead of the main window, known as Main Form Dialogs.

The product group announced this feature way back in February here but only recently have I seen anyone translate this into opening records in this way from the main grid, i.e. overriding the default onclick behavior.  Traditionally there has not been a publicized way to add javascript events to the click handlers of these grids, however this article published in July helps us do just that.  Now, all that is left is to combine concepts from the two articles.

First, we need some javascript code to perform the NavigateTo operation and have it open in a dialog compared to the main frame.  This article documents all the available properties, here is a simple implementation of it.  If you trigger the code from the New+ button as well, you’ll need separate logic for that.  The example I’ll use for this article will help replace the default behavior for the following scenarios:

  1. Opening record forms for main views
  2. Opening record forms for subgrid views
  3. New button for Main record views (not activities, these are separate buttons)
  4. New button for Subgrid record views (not activities)
  5. New button from forms

The Javascript that I use for these use cases needs to handle a variety of inputs/contexts:

  1. For opening records from subgrids and views, we need the selected record moniker and the grid control that opened the record, so that we can refresh it when the record is saved and closed
  2. For the New button on main views, we need to have the entity logical name, and the grid control  to refresh after save and close is pressed.
  3. For the New button on subgrids, we need to have the entity logical name, the record it is being created from, and the subgrid control to be refreshed
  4. For the New button on forms, we just need the entity logical name
function addNewMFDFromSubgrid(gridEntityName, parentEntityName, parentEntityId, primaryControl, gridControl)
{
			let pageInput = {
				pageType: "entityrecord",
				entityName: gridEntityName,
				createFromEntity: 
				{
					entityType:parentEntityName,
					id:parentEntityId
				},
			};
			let pct = {
				value:85,
				unit:"%",
			};
			let navigationOptions = {
				target: 2,
				width: pct,
				height: pct,
			};
			Xrm.Navigation.navigateTo(pageInput, navigationOptions)
            .then(
                function () {
					gridControl.refresh();
                }
            ).catch(
                function (error) {
                    // Handle error
                }
            );
}
function newMFD(entity, gridControl){
			let pageInput = {
				pageType: "entityrecord",
				entityName: entity,
			};
			let pct = {
				value:85,
				unit:"%",
			};
			let navigationOptions = {
				target: 2,
				width: pct,
				height: pct,
			};
			Xrm.Navigation.navigateTo(pageInput, navigationOptions)
            .then(
                function () {
					if(gridControl)gridControl.refresh();
                }
            ).catch(
                function (error) {
                    // Handle error
                }
            );
}
function openMFD(selectedItems, gridControl)
{
	if(!selectedItems)
	{
		let pageInput = {
				pageType: "entityrecord",
				entityName: "new_parcel",
			};
			let pct = {
				value:85,
				unit:"%",
			};
			let navigationOptions = {
				target: 2,
				width: pct,
				height: pct,
			};
			Xrm.Navigation.navigateTo(pageInput, navigationOptions)
            .then(
                function () {
					gridControl.refresh();
                }
            ).catch(
                function (error) {
                    // Handle error
                }
            );
	}
	else{
		let selectedItem = selectedItems[0];
 
		if (selectedItem) { 
			let pageInput = {
				pageType: "entityrecord",
				entityName: selectedItem.TypeName,
				entityId: selectedItem.Id,
			};
			let pct = {
				value:85,
				unit:"%",
			};
			let navigationOptions = {
				target: 2,
				width: pct,
				height: pct,
			};
        Xrm.Navigation.navigateTo(pageInput, navigationOptions)
            .then(
                function () {
                    gridControl.refresh();
                }
            ).catch(
                function (error) {
                    // Handle error
                }
            );
    }
	}
}

To review the specifics of how to wire this up in the ribbon you can view or install the attached managed solution, or the documentation link from earlier, but in summary, to open items from views/grids you’ll need to create a button that has a specific ID, and the Button needs to be attached to a Custom Action with the same ID as the button that executes a custom javascript web resource similar to the sample above.  For this example, I didn’t do the work of hiding the button, although this would be something to implement in a production scenario. 

Hope someone finds this useful

Matt

Let’s block ads! (Why?)

Dynamics 365 Customer Engagement in the Field

Dialogs, Events, form, from, Grid, Main, opening
  • Recent Posts

    • Experimenting to Win with Data
    • twice-impeached POTUS* boasts: “I may even decide to beat [Democrats] for a third time”
    • Understanding Key Facets of Your Master Data; Facet #2: Relationships
    • Quality Match raises $6 million to build better AI datasets
    • Teradata Joins Open Manufacturing Platform
  • Categories

  • Archives

    • March 2021
    • February 2021
    • January 2021
    • December 2020
    • November 2020
    • October 2020
    • September 2020
    • August 2020
    • July 2020
    • June 2020
    • May 2020
    • April 2020
    • March 2020
    • February 2020
    • January 2020
    • December 2019
    • November 2019
    • October 2019
    • September 2019
    • August 2019
    • July 2019
    • June 2019
    • May 2019
    • April 2019
    • March 2019
    • February 2019
    • January 2019
    • December 2018
    • November 2018
    • October 2018
    • September 2018
    • August 2018
    • July 2018
    • June 2018
    • May 2018
    • April 2018
    • March 2018
    • February 2018
    • January 2018
    • December 2017
    • November 2017
    • October 2017
    • September 2017
    • August 2017
    • July 2017
    • June 2017
    • May 2017
    • April 2017
    • March 2017
    • February 2017
    • January 2017
    • December 2016
    • November 2016
    • October 2016
    • September 2016
    • August 2016
    • July 2016
    • June 2016
    • May 2016
    • April 2016
    • March 2016
    • February 2016
    • January 2016
    • December 2015
    • November 2015
    • October 2015
    • September 2015
    • August 2015
    • July 2015
    • June 2015
    • May 2015
    • April 2015
    • March 2015
    • February 2015
    • January 2015
    • December 2014
    • November 2014
© 2021 Business Intelligence Info
Power BI Training | G Com Solutions Limited