Read Only Sub Grid & Editable Sub grid in Dynamics 365

Hello Guys,

In my previous blogs we have seen Duplicate Detection in Dynamics 365 where we covered how you can use OOB feature of D365 to detect duplicate records. Today we will see how we can implement editable sub grid. But before if you are new to our blog then do follow us to know more about Dynamics and Power Platform. Also if you like our blog then please comment and share this blog with your friends.

In Dynamics CRM we have seen many entities sharing parent child relationships and we can create records of child from the parent page. For example Account and Contact Entity. We can create a new contact entity from the Account Form with the help of Sub Grid control.



We can also create sub grid for custom entity and can utilize it in our own way. We will be using Department and Employee Entity for demonstration. Below are the steps:

Step 1:- Login to Dynamics 365 with credentials.

Step 2:- Click on Advance Settings Gear icon. Navigate to Settings -> Solution -> open the solution where you created Department and Employee Entity.




Step 3:- Select Department Entity and open Main Form. Insert one section from the Insert Menu and rename it as below. You can change the properties of the section by selecting it and clicking on Change Properties.



Step 4:- Now Select the Section and click on Insert -> Sub grid. Specify the details as below:



Step 5: Click on Ok. Save the changes and Publish the customization. 

Once Publish is done, open Department Entity and make sure Employees are visible on same entity in sub grid.



So here our employee sub grid is visible as expected. You will notice here that this grid is read only which means you can't edit any cell of that grid. If you want to update any records then you have to open that records and then you can change the field values.

Now we will implement editable sub grid so that you can edit records from the sub grid itself.

Step 6:- Open Department Main form in editor and select Employees sub grid -> Change Properties.



Step 7:- Click on Control Tab and click on Add Control -> Select Editable grid from the list by scrolling -> Add.



Step 8:- Check Web and Tablet radio button and click on OK.



Step 9:- Save the changes and publish the form again. Once Publish is completed. Open Department entity and check the employees sub grid. 



You can now edit the values in the cell also can save it by clicking on save button.

Here you will notice that all the cells are editable and you can change value in those cell. Now we want some of the field should not be editable in the grid. So for this we need to write custom java script.

Step 10: Add a web resource of type JScript and modify it as below:



Here we are disabling Department and Salary field.

Step 11:- Add this web resource in Dynamics. Now open Department Form and select Employee Grid and click on Change Properties. Select Event Tab. We will add gridRowSelected function on OnRecordSelect Event. Make sure you mark the checkbox i.e. Pass execution context as first parameter. Now click on Ok, Save Changes and publish the form.

Now refresh the Department Entity and open any record to check our code is working or not.



You can see, we are able to edit First Name, Last Name , Gender and City but you are not able to edit Department and Salary as these fields are locked.

Hope it helps...













Comments

Post a Comment

Popular posts from this blog

Understanding Sales Process in D365.

Using solution component mover in D365 CRM.