web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / inject subgrid into en...
Power Pages
Answered

inject subgrid into entity form via javascript

(0) ShareShare
ReportReport
Posted on by

Hello fellow developers,

dear @OliverRodrigues 

we are using entity forms on upsert of records in an entitylist (opens in a pop-up-overlay, no webpage required).
i need to show records filtered by fields on this form in a subgrid.

i know i can hide records with javascript, however i thought i could also show the subgrid onCreate (entity forms cannot show subgrids on create) when i inject the subgrid via js.

do i create the table with liquid in a webtemplate (documented) and inject it via js? how do i do that?
using a web-template to insert the entity form and then the subgrid is probably easier, but i will lose the pop-up effect right?
any help is much appreciated
sunny greetings

Categories:
I have the same question (0)
  • nerdifand Profile Picture
    on at

    Hello @OliverRodrigues and @Fubar and @justinburch 
    thank you very much for your help!
    I think this is valuable information for the internet, since i couldnt find anything similar when searching.
    be blessed
    nerdifand

  • Fubar Profile Picture
    8,441 Super User 2025 Season 2 on at

    Just to add to what @OliverRodrigues posted, you can also return JSON to your Ajax call and do all the HTML etc in the Client side (one benefit of this is you can use Client side JS libraries etc).  To do it, it is as per what Oiver has provided but you loop your Fetchxml results and construct the JSON object (rather than constructing the HTML), and then set the mime type on the Web Template to JSON (the mime type is hidden at the bottom of the form and usually not noticed)

     

  • Verified answer
    oliver.rodrigues Profile Picture
    9,368 Most Valuable Professional on at

    hi @nerdifand sorry about the delay, was playing around here and got to what you are looking for.

     

    So basically I created a Web Template that will be responsible for retrieving the subgrid data - my example I am fetching the account records and displaying the results in a table:

    {% fetchxml accountFetch %}
     <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
     <entity name='account'>
     <attribute name='name' />
     <attribute name='telephone1' />
     <attribute name='address1_city' />
     <attribute name='primarycontactid' />
     <attribute name='statecode' />
     <attribute name='accountid' />
     <link-entity name='contact' from='contactid' to='primarycontactid' visible='false' link-type='outer' alias='c'>
     <attribute name='emailaddress1' />
     </link-entity>
     </entity>
     </fetch>
    {% endfetchxml %}
    
    <div class='view-grid'>
     <table aria-relevant='additions' role='grid' class='table table-striped table-fluid'>
     <thead>
     <tr>
     <th style='width:32%;' aria-label='Account Name' tabindex='0'>Account Name<span class='sr-only sort-hint'></span></th>
     <th style='width:10%;' aria-label='Main Phone' tabindex='0'>Main Phone<span class='sr-only sort-hint'></span></th>
     <th style='width:10%;' aria-label='Address 1: City' tabindex='0'>Address 1: City<span class='sr-only sort-hint'></span></th>
     <th style='width:16%;' aria-label='Primary Contact' tabindex='0'>Primary Contact<span class='sr-only sort-hint'></span></th>
     <th style='width:16%;' aria-label='Email (Primary Contact)'>Email (Primary Contact)</th>
     </tr>
     </thead>
     <tbody>
     {% for account in accountFetch.results.entities %}
     <tr data-id='{{ account.id }}'>
     <td data-attribute='name' class='details-link has-tooltip launch-modal'>{{ account.name}}</td>
     <td data-attribute='telephone1' class='details-link has-tooltip launch-modal'>{{ account.telephone1}}</td>
     <td data-attribute='address1_city' class='details-link has-tooltip launch-modal'>{{ account.address1_city}}</td>
     <td data-attribute='primarycontactid' class='details-link has-tooltip launch-modal'>{{ account.primarycontactid.Name }}</td>
     <td data-attribute='c.emailaddress1' class='details-link has-tooltip launch-modal'>{{ account['c.emailaddress1']}}</td>
     </tr>
     {% endfor %}
     </tbody>
     </table>
    </div>

     

    My initial intention was to inject directly to the Insert Entity Form using a liquid tag {% include %}. Not sure why but this was not working as I expected, might be due to the type of data or the timing which things gets evaluated. To overcome this issue I created a Web Page + Page Template to show my table (without header/footer):

    OliverRodrigues_0-1612902257169.png

    Now I am adding a JS to the Insert Entity Form, making an Ajax call to that page, and appending to section in my form:

    $(document).ready(function () {
     AddAccountList();
    });
    
    function AddAccountList()
    {
     try {
     var url = "/account-custom-list/";
     $.ajax({
     method: "GET",
     url: url,
     success: function (data) {
     if (!!data && data.length > 0) {
     $("table[data-name='Accounts']").append(data);
     }
     },
     error: function (jqXHR, textStatus, errorThrown) {
     console.error("Error XXXX: " + jqXHR + ", " + textStatus + ", " + errorThrown);
     }
     });
     } catch (e) {
     console.error("Error XXXX: " + e);
     } 
    };
    

     

    Result:

    OliverRodrigues_1-1612902361603.png

     

     

    I hope this works for you, please let me know.

  • justinburch Profile Picture
    Microsoft Employee on at

    Hi @nerdifand,

    Unless I'm missing something, if there's no relationship and your desire is to have filter options, why not just use an Entity List?

    Just change your Web Template to have both.

    // Typical template
    {% if page.adx_entityform %}
     {% entityform id:page.adx_entityform.id %}
    {% elsif page.adx_webform %}
     {% webform id:page.adx_webform.id %}
    {% else %}
     {% entitylist id:page.adx_entitylist.id %}
    {% endif %}
    
    // Make it
    {% if page.adx_entityform %}
     {% entityform id:page.adx_entityform.id %}
    {% elsif page.adx_webform %}
     {% webform id:page.adx_webform.id %}
    {% endif %}
    <div id="list_div" class="hidden">
    {% if page.adx_entitylist %}
     {% entitylist id:page.adx_entitylist.id %}
    {% endif %}
    </div>
    <script>
     $(function() {
     $(some_selector).after($("#list_div"));
     });
    </script>

     Note I'm going off memory, double-check the liquid in Layout 1 Column. 

  • nerdifand Profile Picture
    on at

    Hello Oliver,

    thank you for your reply.
    its a normal custom entity, nothing special.
    the subgrids on the entity form show records of the same entity. they are not related by a relationship.
    by filtering the records by date fields (effectiv from, valid until), we want to show historic/future records,

    so users can have a look at other records while upsert.


    can i create a subgrid and place it in the form with js?

    $(document).ready(function () {

    create subgrid with fetchxml

     

    put subgrid in form on specific place (maybe $(.selector).after(html subgrid);)
    });

  • oliver.rodrigues Profile Picture
    9,368 Most Valuable Professional on at

    Hi, I actually think it might be the same effort using a Web Page or directly an Entity Form.

    The JS you will write will be place in the Entity Form (insert/modal) so it will run the same way. 

     

    I just trying to get my head around what will be displayed in your subgrid. Can you explain the below:

    • Entity List for Entity X
    • Insert/Create button (opening modal/pop-up)
    • The Insert Entity Form needs to show a subgrid
      • what will the subgrid related to? the new record for entity X does not exist (yet)
      • is it a generic list that you want to display (read-only probably)? 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 51 Super User 2025 Season 2

#2
Jerald Felix Profile Picture

Jerald Felix 25

#2
Lucas001 Profile Picture

Lucas001 25 Super User 2025 Season 2

Last 30 days Overall leaderboard