Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Issue while getting the GridContext on save event of a editable subgrid

Posted on by Microsoft Employee

Hey
I'm facing the problem to get gridContext on save event of a editable subgrid. I need to get the data from editable subgrid and do some operations on the form but while getting the grid from gridContext it shows the error message called "gridContext.getGrid is not a function".

JavaScriptCode.png

I'm referring the below msdn link to get gridContext and grid data.
https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/clientapi-grid-context
https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/grids/gridrowdata

Can anyone please advise on this? It is very urgent.
Any help would be much appreciated.





 

*This post is locked for comments

  • Suggested answer
    Dynamics365 Rocker Profile Picture
    Dynamics365 Rocker 7,755 on at
    RE: Issue while getting the GridContext on save event of a editable subgrid

    You have to update your code as below:

    var formContext = executionContext.getFormContext();

      var gridContext = formContext.getControl("Your Grid Name");

    var myRows=gridContext.getGrid().getRows();

  • Shadendra Profile Picture
    Shadendra 40 on at
    RE: Issue while getting the GridContext on save event of a editable subgrid

    var myRows = gridContext.getGrid().getRows();

    var myRow = myRows.get(arg);///What is ARG here?? which argument?. what i have put here to get row data?

    var gridRowData = myRow.getData();

  • kunalks2003 Profile Picture
    kunalks2003 315 on at
    RE: Issue while getting the GridContext on save event of a editable subgrid

    hi BSD517

    There are some problem with this requirement

    1) Xrm grid only return the current page data so if you have more then 1 page the data will be inconsistent

    2) on save is for a row so it gets the row instance

    possible solution

    you can get the record list from server and then do the calculation. Problem with this approach is that getting data from server is sync and on save will not wait for it. To fix this you need to cancel the current save request by using prevent default and then save data once you get result from the server and done with calculation.You will have to stop the call for onSave next time to make sure it is not blocking the save.

  • BSD517 Profile Picture
    BSD517 on at
    RE: Issue while getting the GridContext on save event of a editable subgrid

    I have a function that runs from the on save of the editable grid.  I want to get the value from a specific field for every row.  If any row has a value of won in that field I need to perform an action.

  • kunalks2003 Profile Picture
    kunalks2003 315 on at
    RE: Issue while getting the GridContext on save event of a editable subgrid

    the context depends on the control/form that is firing the event .

    if the event is onload /onchange/onsave of the form you will get the form context , if the event is from a editable grid onchange you get the row context . please explain what you want to achieve and we may be able to suggest better solution.

  • BSD517 Profile Picture
    BSD517 on at
    RE: Issue while getting the GridContext on save event of a editable subgrid

    Did you ever find a resolution for this?  I'm having the same problem.  

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Issue while getting the GridContext on save event of a editable subgrid

    Having the same issue with the "onChange" event.

    This is an issue with Microsoft's documentation here: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/clientapi-grid-context

    That link gives an example to get "gridContext".

    This link gives an example to "getGrid" from "gridContext": https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/grids/gridcontrol/getgrid

    However, the "gridContext" from "onChange" does not have a "getGrid" function.

    @Microsoft - please update your documentation to be more clear.

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Issue while getting the GridContext on save event of a editable subgrid

    Hi jalak,

    Check the below link. The grid context depends upon from where you are calling the javascript.

    docs.microsoft.com/.../clientapi-grid-context

    Once you get the gridcontex, you can get the rows as well -

    docs.microsoft.com/.../gridrowdata

    Hope this helps.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Issue while getting the GridContext on save event of a editable subgrid

    I can see in the second line of screenshot retrieving  formContext but you gave the name gridcontext.

            function onEmployeeDetailsSave(executionContext) {
                var formContext = executionContext.getFormContext(); // get the form Context
                var gridContext = formContext.getControl("Contacts"); // get the grid context provinding subgrid name
                var myRows = gridContext.getGrid().getRows();
            }


  • kunalks2003 Profile Picture
    kunalks2003 315 on at
    RE: Issue while getting the GridContext on save event of a editable subgrid

    Can you please tell what you are trying to achieve. the the form Context  is of Grid Row and you can not access the grid from it .

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,064 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans