web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Subgrid calculation

(0) ShareShare
ReportReport
Posted on by 595

i'm trying to perform some calcuation on editable subgrid "QuestionGrid"... refer below code, there upto alert(count); i'm getting, while retrieving defectcritical column value it is showing getGrid null error... 

function Demerits(executionContext) {  
    //subgrid unique name : "QuestionGrid"
    var formContext = executionContext.getFormContext();
    var gridContext = formContext.getControl("QuestionGrid");
    var count = gridContext.getGrid().getTotalRecordCount();
    console.log("Total Questions:"+count);
    alert("Total Questions:"+count);
    for(i = 0; i < count;i++) 
{
    //Critical values sum
var defectcritical = formContext.getControl("QuestionGrid").getGrid().getRows().get(i).getData().getEntity().getAttributes().get("systrent_defectcritical").getValue();//not getting this line
var criticalsum = criticalsum + defectcritical;
}
}
I have the same question (0)
  • Suggested answer
    Linn Zaw Win Profile Picture
    3,407 on at

    GridRow.getData client API is deprecated and it may not work well in Unified Interface.
    formContext.getControl("QuestionGrid").getGrid().getRows().get(i).getData()

    https://docs.microsoft.com/en-us/power-platform/important-changes-coming#:~:text=GridRow.getData

    Please consider changing your script to call the Xrm.WebApi and calculate the summation of the defectcritical values from all child records. You can find the sample codes in the links below.

    https://www.crmug.com/communities/community-home/digestviewer/viewthread?GroupId=1285&MessageKey=5c07b941-9c31-4990-afda-1a034a1329ee&CommunityKey=dc83c23b-ede0-4070-ae7a-dd90859148a6&tab=digestviewer&ReturnUrl=%2Fresources%2Fforum

    https://www.inogic.com/blog/2018/01/dynamics-365-v9-0-xrm-webapi-crud-operations-part-1/

  • Abhilash M abi Profile Picture
    595 on at

    Upto alert i'm getting using deprecated methods only.. i tried using new methods but not getting anything...

  • Linn Zaw Win Profile Picture
    3,407 on at

    Before alert, the code that you used is gridContext.getGrid().getTotalRecordCount();

    getTotalRecordCount is still supported and not deprecated.

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/grids/grid/gettotalrecordcount

    There is no new method to replace the deprecated GridRow.getData client API. Please consider changing your script to call the Xrm.WebApi as mentioned in the reply above.

  • Suggested answer
    Linn Zaw Win Profile Picture
    3,407 on at

    Apparently, data property of GridRow object is the replacement for getData() method.

    Here is the updated script of yours after replacing the deprecated methods. It should be working fine. But be aware that GridAttribute (.attributes.get("systrent_defectcritical").getValue() part) is only supported for editable grids according to the documentation and it may break on read-only grids in future upgrades.

    function Demerits(executionContext)
    {
    	var formContext = LZW.Xrm.Test.executionContext.getFormContext();
    	var gridContext = formContext.getControl("QuestionGrid");
    	var count = gridContext.getGrid().getTotalRecordCount();
    	var criticalsum = 0;
    	for(var i = 0; i < count; i  ) 
    	{
    		var defectcritical = gridContext.getGrid().getRows().get(i).data.entity.attributes.get("systrent_defectcritical").getValue();
    		criticalsum  = defectcritical;
    	}
    	Xrm.Navigation.openAlertDialog( { text: criticalsum });
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 176

#2
ManoVerse Profile Picture

ManoVerse 56 Super User 2026 Season 1

#3
Niki Patel Profile Picture

Niki Patel 42

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans