Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Subgrid field value calculation

Posted on by 595

I'm trying to get editable subgrid record to perform some calculation using javascript..

my javascript code:

function Demerits(executionContext) {  
    
    //subgrid unique name : "Subgrid_2"
    var formContext = executionContext.getFormContext();
    var gridContext = formContext.getControl("Subgrid_2");
    var count = gridContext.getGrid().getTotalRecordCount();
    console.log("Total Questions:"+count);
    alert("Total Questions:"+count);
}

 always showing getGrid is null.. any suggessions.... 

  • Abhilash M abi Profile Picture
    Abhilash M abi 595 on at
    RE: Subgrid field value calculation

    tried with that as well.. but didn't work..

    i changed unique name of subgrid also and tried... that also didn't work...

  • Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Subgrid field value calculation

    Hi,

    Found the issue.

    Try to select Display label on the Form checkbox on sub grid properties. it will work

    If found helpful, Please mark my answer verified.

  • Abhilash M abi Profile Picture
    Abhilash M abi 595 on at
    RE: Subgrid field value calculation

    i used on save of subgrid..

    my subgrid unique name is "Subgrid_2"... i give that as a parameter.. but why it i returning null..? should i change the subgrid name anything else?

  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Subgrid field value calculation

    Hi,

    On which event you have attached your code?

    I just checked your code on my trial on Account entity Contact sugrid and see result below .

    function Demerits(executionContext) {  

       //subgrid unique name : "Contacts"

       var formContext = executionContext.getFormContext();

       var gridContext = formContext.getControl("Contacts");

       var count = gridContext.getGrid().getTotalRecordCount();

       console.log("Total Questions:"+count);

    console.table("Total Questions:"+count);

       alert("Total Questions:"+count);

    }

    Form - Onload -> getTotalRecordCount() - Returns zero

    Form - OnSave -> getTotalRecordCount - Returns exact number of count

    Sugbrid OnChange -> getTotalRecordCount - Returns exact number of count

    If found helpful, Please mark my answer verified.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans