Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

Getting related data shown in subgrid with JavaScript

Posted on by 15

Hi all,

I'm trying to create a custom button in a form subgrid that copies the data from one of the columns.

It'd be easy if the property I want to copy was from the directly-related entity, but in my case, the column comes from a level below (linked to the related entity), so it's not listed on the row.getData().getEntity().attributes.getAll();

@Edit: Example

So here I have a view on the Contact form showing the associated Accounts.

The second column is a lookup field of the entity for its parent account.
The third column is the email address of its parent account. That is the value I want.

Annotation-2020_2D00_05_2D00_22-085920.jpg

I created a ribbon button for this subgrid passing the SelectedControl as the parameter, with the following code:

function getEmail(control) {
    var rows = control.getGrid().getRows();
    rows.forEach(function (row, i) {
        var data = row.getData().getEntity().attributes.getAll();
        console.log(data);
    });
}

But as the log shows, the column with the associated value is not being fetched:

Annotation-2020_2D00_05_2D00_22-090928.jpg

I know that I could fetch the data using REST, but since the data is already being shown in the subgrid, it must be a way to access it without sending another request.

I'm also trying to avoid unsupported solutions, but they are welcome if there's no supported way of doing that.

Any ideas?

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Getting related data shown in subgrid with JavaScript

    Hi Cassio,

    It seems that "rowData.getEntity().attributes" will only return fields of primary entity, even if attributes of related entity are actually included in fetchXml parameter.

    I didn't find any note which talks about the limitation after I have searched all methods and attributes of grid control from doc and many previous threads and blog articles.

    In a word, it could be by design, you might still need a REST call to get related entity data to meet your requirement.

    Regards,

    Clofly

  • cmilanelo Profile Picture
    cmilanelo 15 on at
    RE: Getting related data shown in subgrid with JavaScript

    Hi Clofly Mao,

    I just edited my original post with a full example.

    Thank you

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Getting related data shown in subgrid with JavaScript

    Hi Cassio,

    Could you share more details about "but in my case, the column comes from a level below (linked to the related entity)"?

    As per my understanding, we could only get listed columns in subgrid.

    Please add a new column if you would like to get more field from related entity.

    Regards,

    Clofly

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans