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".
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
You have to update your code as below:
var formContext = executionContext.getFormContext();
var gridContext = formContext.getControl("Your Grid Name");
var myRows=gridContext.getGrid().getRows();
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();
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.
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.
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.
Did you ever find a resolution for this? I'm having the same problem.
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.
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.
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(); }
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 .
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,232 Super User 2024 Season 2
Martin Dráb 230,064 Most Valuable Professional
nmaenpaa 101,156