Friday, January 20, 2023

How to get SubGird Record Count with Webresource in Dynamics CRM

Introduction:


In this Blog, we will see how to Get SubGrid Record Count in MSCRM or Model Driven App using WebResource.


Implementation Steps:

 

1. Navigate to https://make.powerapps.com

 

2. Create or Open any Existing Solution

 

3. Open the Table/Entity where you want to get count of SubGrid in my case am taking Account Table

 

rampprakash_0-1674210056707.png

 

4. As per the ScreenShot there is 4 Records available so i need to show as a popup with Count as 4

 

5. So First Step i will take the Sub Grid Name

 

6. Open the Form where your SubGrid Exists 

 

rampprakash_1-1674210171186.png

 

 

7. Based on the Above ScreenShot the Name of the SubGrid is Contacts

 

8. Now Lets Start Writing the JavaScript

 

9. Open Your Visual Studio or VS Code and Write the Below Function

 

function getsubgridcount(executionContext) {
    setTimeout(function () {
        var formContext = executionContext.getFormContext();
        if (formContext !== null && formContext != "undefined") {
            var accountgridname = "Contacts";
            var count = formContext.getControl(accountgridname).getGrid().getTotalRecordCount();
            alert(count);
        }
    }, 15000);
}

 

10. Now Create a JavaScript (Web Resource) in CRM 

 

rampprakash_2-1674210958690.png

 

11. Click Save and Publish

 

12. Now Open the Same Account Form and Add the JavaScript Library in the Form

 

rampprakash_3-1674211210777.png

 

13. Now Add Function in the OnLoad Operation

 

rampprakash_4-1674211290953.png

 

14. Once Done Click Save and Publish

 

15. Now Open the Account Table and Open a Record you will see the alert message over there :slightly_smiling_face:

 

rampprakash_5-1674211665753.png

 

 

That's it :slightly_smiling_face:

No comments:

Post a Comment

Day 11 - Customizing Option Sets Dropdown Fields with JavaScript

  In this Blog, we will see how to Customizing Option Sets Dropdown Fields with JavaScript label1 = formContext.getAttribute( "bosch_op...