Hello everybody,
I try to get the value of the selected record in subgrid . Here is the code I use, but I get this error:
"Unable to get property 'getData' of undefined or null"
I am looking forward to your answers.
Regards
hi,
function subgriddata(executionContext) {
var entityObject = executionContext.getFormContext().data.entity;
var monthlyCost = entityObject.attributes.getByName("monthlyunit");
}
try this
Hi Partner,
1. If you want to get value from multiple selected rows:
The following code will only return the first record attributes due to getAll()[0]
var selectedRecord = Xrm.Page.getControl("Name").getGrid().getSelectedRows().getAll()[0].getData().getEntity();
var attributeValue = selectedRecord.attributes.getByName("attr").getValue();
alert(attributeValue);
So you should also remove getAll()[] function .
2. I just use Console.log to output all selected rows with specific attribute in console to test whether code is working, you could push them into an array with your requirement.
3. It seems that your attribute(or the related entity's field) is a Lookup field, it's a reference type,
so then you could try
selectedRecord.attributes.getByName("attr").getValue()[0].name
or
row.getData().getEntity().attributes.get("attr").getValue()[0].name
to get its name value.
Regards,
Clofly
Thanks for your answer.
I have tried it - as alert get [object Object] and not the name of the dataset.
What does the line that starts with "console.log" do?
Because in my case I need several values from the selected dataset, because I want to create a dataset with these values.
Best Regards
Hi Partner,
getSelectedRows returns a collection, please iterate it with forEach function.
You could try code below, it works from my test:
var rows = Xrm.Page.getControl("Name").getGrid().getSelectedRows();
rows.forEach(function (row, i) {
console.log(row.getData().getEntity().attributes.get("attribute").getValue());
});
And argument in getControl should be Name property of sub grid.
Supplement:
Please delete selectedRecord.getAttributes().getAll(), simply with selectedRecord.attributes.getByName("attr").getValue(),
the whole statement could be this:
Xrm.Page.getControl("Name").getGrid().getSelectedRows().getAll()[0].getData().getEntity().attributes.getByName("attr").getValue();
Regards,
Clofly
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,240 Super User 2024 Season 2
Martin Dráb 230,104 Most Valuable Professional
nmaenpaa 101,156