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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Sub Grid Issue with data loading using JavaScript

(0) ShareShare
ReportReport
Posted on by 242

HI,

I am trying to load sub grid data based on lookup selecting but its not loading data in sub grid.

function filterSubGrid(subgridName, fetchXml, attempts) {
   
    if (attempts < 0) { return; }

    var crmWindow = parent.Xrm.Internal.isTurboForm() ? parent.window : window;

    // Get the subgrid element to filter
    var subgrid = crmWindow.document.getElementById(subgridName);
    if (subgrid == null || subgrid.control == null) {
      
        setTimeout(function () { filterSubGrid(subgridName, fetchXml, (attempts || 10) - 1); }, 500);
        return;
    }

  
    subgrid.control.SetParameter("fetchXml", fetchXml);
    subgrid.control.refresh();
}


function filterAccountGrid() {
	
	
	var lookupObj = Xrm.Page.getAttribute("aah_sectionidid"); //Check for Lookup Object
	if (lookupObj != null) {
	var lookupObjValue = lookupObj.getValue();//Check for Lookup Value
	if (lookupObjValue != null) {
	var lookupEntityType = lookupObjValue[0].entityType, //To get EntityName
	lookupRecordGuid = lookupObjValue[0].id, // To get record GUID
	lookupRecordName = lookupObjValue[0].name; //To get record 
	
var fetchXml = 	 '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">  '  + 
 '     <entity name="aah_question">  '  + 
 '       <attribute name="aah_questionid" />  '  + 
 '       <attribute name="aah_name" />  '  + 
 '       <attribute name="createdon" />  '  + 
 '       <order attribute="aah_name" descending="false" />  '  + 
 '       <filter type="and">  '  + 
 '         <condition attribute="aah_sectionid" operator="eq"  uiname='+'"'+ lookupRecordName +'"'+'  uitype="aah_section" value="'+ lookupRecordGuid +'" />'   + 
 '       </filter>  '  + 
 '     </entity>  '  + 
 '  </fetch>  ' ; 

     filterSubGrid("Questions", fetchXml);
  

}
	}
}

xml output is like 

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">       <entity name="aah_question">         <attribute name="aah_questionid" />         <attribute name="aah_name" />         <attribute name="createdon" />         <order attribute="aah_name" descending="false" />         <filter type="and">           <condition attribute="aah_sectionid" operator="eq"  uiname="General Health"  uitype="aah_section" value="{3FFBE419-C066-E911-A975-000D3AF06B36}" />       </filter>       </entity>    </fetch>  

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi,

    Have a look below old thread ,my personal opinion you shoud avoid the way you are filtering ,prepare your data accordingly to display in subgrid.

    community.dynamics.com/.../299697

    goutamdascrm.wordpress.com/.../what-is-stopping-you-to-use-out-of-the-box-subgrid-in-dynamics-365

  • madiri Profile Picture
    242 on at

    HI Goutam,As Per your Links i would prefer plugin but as per my scenario i have section entity and question entity i am giving section lookup 1:n to question entity so we have another entity sectionbasedquestion which i would like select section lookup when select one section it should populate questions in sub grid with respect to section and if i want to remove  one question in   1:n subgrid i want to remove that question is your plugin suite for this?

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    I think you should use quick view form in that case , no code approach. Go to the lookup entity and create a quick view form and add a subgrid of the entity which you want to display. Once you created quick view form come back to the entity where your lookup exists and  add the quick view form instead of  subgrid here where you are doing filtering . So it will render subgrid inside quick view form and accordingly which lookup you selected.

  • madiri Profile Picture
    242 on at

    No Goutam if i create a quick view form it will create record section entity which i don't want i will  select sections lookup 1:n which is there in question master  so i need to show that  question data if i want remove one question it should not reflect to questions master it show reflect to section question entity with having relation with question master how can i achieve?

  • gdas Profile Picture
    50,091 Moderator on at

    As per my understanding following you can try -

    Section Entity -->  Create Quick View Form where add "Question" subgrid

    Question  --> You have Lookup of Section , that means section can have multiple Question so you can easily add the question subgrid in the quick view form of section entity.

    SectionBaseQuestion -->Section Lookup  --> Add quick view form of "Section" Entity Choose the relation.

    By doing above you will add quick view form of section but you can see the subgrid of Question and can add the question record. So you can create question record for selected section from the SectionBaseQuestion entity.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    I just tried your scenario for second time make sure and its working for me  -

    Here is the steps I followed  -

    1. Create Section , Question , SectionBaseQuestion Entity.

    2019_2D00_04_2D00_28_5F00_1_2D00_11_2D00_57.png

    2. Create a lookup field (section entity) in the Question entity and add Question main form.

    2019_2D00_04_2D00_28_5F00_0_2D00_55_2D00_33.png

    3. Create a lookup field(section entity ) in the SectionBaseQuestion and add in the main form.

    2019_2D00_04_2D00_28_5F00_0_2D00_56_2D00_32.png

    4.Create a quick view form in the section entity and add the subgrid of question entity.

    2019_2D00_04_2D00_28_5F00_0_2D00_59_2D00_30.png

    2019_2D00_04_2D00_28_5F00_1_2D00_04_2D00_04.png

    5.Add the quick view form of the Section entity in the SectionBaseQuestion entity main form.

    2019_2D00_04_2D00_28_5F00_1_2D00_06_2D00_38.png

    2019_2D00_04_2D00_28_5F00_1_2D00_07_2D00_06.png

    Did  publish all customization - see the result -

    2019_2D00_04_2D00_28_5F00_1_2D00_11_2D00_57.png

    2019_2D00_04_2D00_28_5F00_1_2D00_12_2D00_16.png

    2019_2D00_04_2D00_28_5F00_1_2D00_12_2D00_57.png

  • madiri Profile Picture
    242 on at

    Goutam,Actually what i need auto populate  questions  based on section lookup  no need to select a question.

  • gdas Profile Picture
    50,091 Moderator on at

    Did you tried the steps which I shared  ? its auto populating on change of section lookup you can see the screenshot.

  • madiri Profile Picture
    242 on at

    Goutam i tried its auto populate questions  but if i delete question from quick view its  deleting that question from question entity   which i don't need like that it should only delete from SectionBaseQuestion  entity  if i place sub grid it will remove a question from only SectionBaseQuestion entity but i won't delete  question from question entity. let  me take an example there are two schools one school having science exam and other school also having science exam but different questions so i will manage this from SectionBaseQuestion entity which actually wont delete question from question entity i should only remove from SectionBaseQuestion entity but i want to populate questions based on section and schools.I hope you understand what i need  can you help on this please.

  • gdas Profile Picture
    50,091 Moderator on at

    There is no soft remove functionality available in D365 in the subgrid   , the only options is to disassociate  the questions records  from  sections if you dont want see  records in  subgrid.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans