cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ronkochanowski
Frequent Visitor

Model-Driven App Loading Grid Detail to Custom Page

Hello all,

 

I've been searching for a way to accomplish this and have not found a good solution. It seems that someone out there might have tried to do something similar in the past...

Situation:

  • I have a model-driven view (grid) that contains the Primary Contact's Email.
  • I have a custom page that has a field to hold all of the emails of the records selected in the grid.
  • I am successfully loading the grid to a panel on the right and passing the selected items from the grid to page, but the only item passed is the recordId of the account.
  • Microsoft documentation states that if we are trying to get the GridContext of the model-driven app to be available to the custom page we are to add the parameter "SelectedControl" to the Command button that displays the custom page.
  • I'm also passing the parameter "SelectedControlsSelectedItemReferences", which returns the Id, Name, TypeName, and TypeCode for each selected row in the grid.

Issue:

I cannot figure out how to access the grid column that contains the Primary Contact's email address for the selected rows.

 

It seems as though I should be able to do something like this:

 

function OpenSendEmail(selectedControl,selectedItems,selectedItemCount) {
	var gridContext = selectedControl;
	var selectedEmail = gridContext.getAttribute('emailaddress1');
	

// display side pane
	if (selectedItems) {
		var paneInput = {
			title: "Send Email",
			paneId: "SendEmail",
			canClose: false,
			width: 600
		};
		var navigationOptions = {
			pageType: "custom",
			name: "vc_sendemail_aed9d",
			entityName: selectedControl._entityName
		};
	};
	
	Xrm.App.sidePanes.createPane(paneInput).then((pane) => {
		pane.navigate(navigationOptions)
	});

	console.log(selectedControl);
	console.log(selectedItems);
	console.log(selectedEmail);
	console.log(selectedItemCount);
	console.log(navigationOptions);

}

 

But the third line, throws an error stating that gridContext.getAttribute is not a function. With that, how do I grab the value contained in the 'emailaddress1' column of each selected row?

1 ACCEPTED SOLUTION

Accepted Solutions
cha_cha
Super User
Super User

Hello @ronkochanowski 

 

Based on this documentation, I think you need to use more methods within GridContext Object. I've done a couple of ReactJS projects in the past month so have gone thru this but not in Model Driven Apps. Your code should flow like this:

 

   //Choose 1 get rows - use the getControl method and pass the grid name.
   var allRows = gridContext.getGrid().getRows(); //all rows
   var allRows = gridContext.getGrid().getSelectedRows(); //selected rows only


   //loop through rows and get the attribute collection
   allRows.forEach(function (row, rowIndex) {

       //get the attribute Collection
       var attributeColl = row.getData().getEntity().attributes;
   
       //get the value
       var emailVar = attributeColl.getByName("emailAddress1").getValue();


                   

 

My references are from the Dynamics community.

https://community.dynamics.com/365/f/dynamics-365-general-forum/363243/get-the-value-of-the-selected...

https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/371356/need-help-finishing-javascr...

 


  ✔️
Just in case you my answer helped you solve your problem, please mark/accept this as a SOLUTION This helps community members if they experience a similar issue in the future.

 

  🔗
🕸bistek.space  🐦 @cha_bistek  📺 @BisTekSpace 

 

 

 

 


 
Just in case you my answer helped you solve your problem, please mark/accept this as a SOLUTION This helps community members if they experience a similar issue in the future.

 
bistek.space   @charv3n    @BisTekSpace 

View solution in original post

2 REPLIES 2
cha_cha
Super User
Super User

Hello @ronkochanowski 

 

Based on this documentation, I think you need to use more methods within GridContext Object. I've done a couple of ReactJS projects in the past month so have gone thru this but not in Model Driven Apps. Your code should flow like this:

 

   //Choose 1 get rows - use the getControl method and pass the grid name.
   var allRows = gridContext.getGrid().getRows(); //all rows
   var allRows = gridContext.getGrid().getSelectedRows(); //selected rows only


   //loop through rows and get the attribute collection
   allRows.forEach(function (row, rowIndex) {

       //get the attribute Collection
       var attributeColl = row.getData().getEntity().attributes;
   
       //get the value
       var emailVar = attributeColl.getByName("emailAddress1").getValue();


                   

 

My references are from the Dynamics community.

https://community.dynamics.com/365/f/dynamics-365-general-forum/363243/get-the-value-of-the-selected...

https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/371356/need-help-finishing-javascr...

 


  ✔️
Just in case you my answer helped you solve your problem, please mark/accept this as a SOLUTION This helps community members if they experience a similar issue in the future.

 

  🔗
🕸bistek.space  🐦 @cha_bistek  📺 @BisTekSpace 

 

 

 

 


 
Just in case you my answer helped you solve your problem, please mark/accept this as a SOLUTION This helps community members if they experience a similar issue in the future.

 
bistek.space   @charv3n    @BisTekSpace 

@cha_cha ,

Wow!  Thank you!  This was actually pretty straight forward.  I can now see the collection with the columns from the Account entity.  Next, drilling into the Contact entity to grab the Primary Contact's email, which isn't revealed in the collection.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,784)