# How to populate data into navigateTo() ❓✅

Whether you're a Power Apps developer looking to enhance the user experience or an application consultant aiming to optimize business processes, this blog post will equip you with the knowledge and tools to master data population within the "[navigateTo](https://learn.microsoft.com/de-de/power-apps/developer/model-driven-apps/clientapi/reference/xrm-navigation/navigateto)" function.

## #1. Introduction - My scenario

By default there is a feature in Dynamics 365 called "[Connections](https://learn.microsoft.com/en-us/dynamics365/customerengagement/on-premises/basics/create-connections-view-relationships-between-records)".

> "\[...\] you can create and view the relationships between records for many entities using **Connect**. Connections enable you to easily associate users, contacts, quotes, sales orders, and many other entity records with each other. When you open a record and select **Connections**, you can view all of the connections between it and other records."

So when a client asks if he can, for example, relate a contact with several accounts, I usually refer to the connections. Of course, a separate relationship can be created for this, but why not use the standard if it is already there❓

So it was clear pretty quickly: we use the standard and thus the connections. 💡

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685701263402/1c48be06-99de-4f36-813e-0a39b3dca168.gif align="center")

There is already a "Connect" button on the account form...

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685701106785/77717e91-559b-41dc-9a84-1b15fd3a6244.png align="center")

...but it opens a new form when pressed; all pending changes must be saved or discarded immediately. 🥲

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685703646571/40e4914b-4a82-4231-b8dc-f7c66ef57f71.png align="center")

For the user, this kind of user experience is not the best, we can improve something there!

## #2. Target

Wouldn't it be much better if we could leave the form open and also have the option to create a connection? 🚀🚀🚀

True, you could say "use canvas pages - WYSIWYG is the best thing ever!!", but handling lots of data like contacts in my case is possible, but not that great in canvas pages. It is faster to reuse things that are already there! 💡 Don't try to reinvent the wheel when it's not needed. ⛔💩

True, you could say "use the quick create form", but unfortunately this is not available for connections. 😉

Besides, main forms are much nicer than quick create forms anyway.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685704003165/3d2c781f-ac8d-4581-909e-b4bd4cbbf3e1.gif align="center")

So instead of opening a new form like this:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685704040405/ba8624f6-6f07-44ee-a6e4-8af8a17e34b5.png align="center")

I would love to have something like this:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685704189441/25dca27c-88d7-4f4a-8d00-470c20ce8bfd.png align="center")

## #3. Specialties

As you may know, when you press the "connect" button, the standard populates the "Connected From" field with the record from which you need the button.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685704537669/ab99aa45-cc47-4995-bb28-4783e526a71b.png align="center")

That's cool 😎, that saves time ⏱️, we need that too 🤓!

## #4. Implementation

So... how do we do that?  
First, let's create a button!

### #4.1 Creating a button using the command bar editor

For those of you who don't know how to open the command bar editor, please follow this documentation provided by Microsoft: [Open the command designer to edit a command bar](https://learn.microsoft.com/en-us/power-apps/maker/model-driven-apps/use-command-designer#open-the-command-designer-to-edit-a-command-bar).

* Create a new command button
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685708719886/4a32e87b-b220-46d3-bb1e-03622eaa5458.png align="center")
    
* Set the properties of the newly created button
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685708745429/bc917183-37be-4a02-8828-eed7c081616f.png align="center")
    

But wait... where do I get the script from ❗❓

Ok... let's create one... 🦊

### #4.2 Creating the JavaScript file

Just copy this and you'll be happy forever.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685705540240/0f34ad03-19a0-4826-993c-8a83b630bf38.gif align="center")

```javascript
function OpenCreateConnectionAsModal(formContext) {

	var pageInput = {
	
		// open the connection form
		pageType: "entityrecord",
		entityName: "connection",
		
		// populate data
		data: {

            // ID
			record1id: formContext.data.entity.getId(), 

            // Name of the record
            // "name" is attribute
            // Could also be something like "subject" or "new_name"
			record1idname: formContext.getAttribute("name")?.getValue(),
            
            // EntityLogicalName
			record1idtype: formContext.data.entity.getEntityName()			
		}
	};

	var navigationOptions = {
	
		// open as modal
		target: 2,
		
		// define height in percent
		height: { 
			value: 80, 
			unit: "%" 
		},
		
		// define width in percent
		width: { 
			value: 70, 
			unit: "%" 
		},
		
		// centered
		position: 1
	};

	Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(
		function success() {
			// Run code on success
		},
		function error() {
			// Handle errors
		}
	);
}
```

With the script in hand, we're almost done ✅... just deposit it briefly in the command button and enjoy. 🏖️🥂🚀

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685706473469/c602a466-ba63-4ee5-8ca5-d7b85416c50a.png align="center")

⚠️ And don't forget to set "PrimaryControl" as your first parameter!!!

After a quick publish, we're done! 🤩

If you don't want the "old" connection button to be visible (if available like it is for the account), just open the good old [Ribbon Workbench](https://www.xrmtoolbox.com/plugins/RibbonWorkbench2016/) and hide it. If you don't know how to use it: [click here to get wisdom](https://ribbonworkbench.uservoice.com/).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685706784229/82ab3ad5-2561-4939-9b0e-dc98099fd319.png align="center")

### #4.3 Result

In conclusion, by taking a step beyond the default "Create Connection" experience in the Power Platform, we've made significant 💪 strides in enhancing the overall user experience. Through thoughtful 💭 customization and optimization, we've created a streamlined process that boosts productivity and improves workflow. Let's continue to challenge the status quo, explore innovative solutions, and empower ourselves to create exceptional user experiences within the Power Platform. 🚀 Together, we can revolutionize the way we work and unlock the full potential of this powerful tool.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685707299151/9fddd8f8-bd91-4590-88f5-a3b03df4683e.gif align="center")

That is something ChatGPT would say...

... I would say it was a small step in the right direction to improve the user experience bit by bit.

But what about you? If you have any questions ❓ or suggestions ❗ for improvement 🚀, please contact me - I'm happy to hear from you! 😊

I'm out ...

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685707552856/bce49e08-74e0-4bed-ae85-346e3dce478d.gif align="center")
