Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

How to get the data from a Subgrid to the HTML webresource

(0) ShareShare
ReportReport
Posted on by 11
I have tab in a Table Items. At this tab there are two webresources: image and HTML.
It looks like this
 
I would like to get to the blue fields data from the subgrid elements, from the table Warranties. Subgrid is in the same tab with a webresource.
The Actual Date and the Planned Date values for the Complex Type should be under the Complex picture in the fielsd with the appropriate names and for the simple type appropriately.
As far as I understand, I should add the part of the Java Script code to the HTML code and get the needed data.
And also, can in my case be the JS file, link to which will be added to the HTML web resource. Theoretically to get the Data from the Script I should add the JS webresource on Script load?
I would be grateful for the hint, which functions should I use, which actions sequesnce as well.
 
 
  • Verified answer
    Dengliang Li Profile Picture
    Dengliang Li Microsoft Employee on at
    How to get the data from a Subgrid to the HTML webresource
    Hi,
     
    Yes, you can retrieve the data from the subgrid in the HTML web resource and then pass it into the HTML.
    In my test, I passed the Warranty Actual Date and Warranty Planned Date values for records with a Warranty Type of simple in the case subgrid of the contact entity into the HTML web resource.
    The code is shown below.
     
    <body>
        <img src="https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1Mu3b?ver=5c31" alt="">
        <div >
            <label for="Actual Date">Actual Date</label>
            <input type="text" id="Acutal Date">
        </div>
        <br>
        <div>
            <label for="Planned Date">Planned Date</label>
            <input type="text" id="Planned Date">
        </div>
    </body>
     
    <script>
        window.onload= load;
            function load(){
     
            //Get the Actual Date and Planned Date in an HTML web resource.
            var actualDate = window.window.document.getElementById("Acutal Date");
            var plannedDate = window.window.document.getElementById("Planned Date");
           
            //Gets all row records of the case subgrid.
            var gridControl = window.top.Xrm.Page.getControl("contactcasessgrid");
            var gridRows = gridControl.getGrid().getRows().get();
     
            //If no row records are fetched, wait 4 seconds for the case subgrid to finish loading to execute the next step.
            if(gridRows.length ===0){
                setTimeout(function(){
                   
                    //Iterate through all rows of records
                    for(let item of gridRows){
     
                    //Look for the record for Warranty Type as simple.
                    let type = item.getAttribute("cra21_warrantytype").getValue();
                   
                    if(type !== null&&type===0){
                    //Populate the HTML web resource with the values of Actual Date and Planned Date for records with a Warranty Type of simple.
                    actualDate.value = item.getAttribute("cra21_warrantyactualdate").getValue()
                    plannedDate.value = item.getAttribute("cra21_warrantyplanneddate").getValue()
                }
            }
                },4000);            
            }        
        }
    </script>
     
     
     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more.
    If you have further questions, please feel free to contact me .
     
    Best Regards,
    Dengliang Li
     

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans