locked
Populate subgrid programatically in form onLoad RRS feed

  • Question

  • I have a subgrid on an order form that looks up to Customer Quotes. I have written javascript that loads all customer quotes relevant to this order. There is no direct relationship between Customer Quotes and Orders - I get another lookup value from the Order form (Enquiry id), and this value is also on the Customer Quote entity, so I pass the enquiry id into my query, and I'm getting the correct Customer Quotes back.

    I need to know now how to populate a subgrid in the onLoad, which I have no idea to do. I have already written code to filter a lookup, using addPreSearch - so maybe it's something similar for a subgrid??

    Here's my javascript code that gets the Customer Quotes back:

    function QueryCustomerQuotes () {
    
    
      	var enquirylookupid;
        var enquirylookup = new Array();
        enquirylookup = Xrm.Page.getAttribute("new_enquiryid").getValue();
    
        if (enquirylookup != null) {
    
            enquirylookupid = enquirylookup[0].id;
       
    		enquirylookupid = enquirylookupid.replace('{', '').replace('}', '');
    			
    		var tempUrl = Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/";
    		var queryUrl = tempUrl + "new_customerquoteSet?$select=new_VendorId,new_VendorQuoteDetails, new_LeadTime, CreatedOn,&$filter=new_EnquiryId/Id eq (Guid'" + enquirylookupid + "')";
    	alert("queryUrl: " + queryUrl);
    		// make the ajax call
    		$.ajax({
    			type: "GET",
    			contentType: "application/json; charset=utf-8",
    			datatype: "json",
    			url: queryUrl,
    			beforeSend: function (XMLHttpRequest) {
    				//Specifying this header ensures that the results will be returned as JSON.
    				XMLHttpRequest.setRequestHeader("Accept", "application/json");
    			},
    			success: function (data, textStatus, XmlHttpRequest) {
    				if (data && data.d != null && data.d.results != null) {
    					var records = data.d.results;					
    					for (var i = 0; i < records.length; i++) {
    						
    					}
    				}
    			},
    			error: function (XmlHttpRequest, textStatus, errorThrown) {
    				alert("ERROR: " + errorThrown);
    			}
    		});
    	}
     
    }
    Thank you


    Friday, April 25, 2014 4:41 PM

All replies

  • You can change the data in a subgrid by doing something like this:

    var subGrid = document.getElementById(subGridName);
            subGrid.control.SetParameter("fetchXml", fetchXML);
            subGrid.control.refresh();


    Sunday, April 27, 2014 5:45 AM