Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

assign dynamic filtered view to subgrid in Dynamics 365 online

Posted on by Microsoft Employee

Hi All,

I have one requirement which says, There is a lookup field "Product". One product have many "lots numbers".

Whenever user selects any product, its respective lots numbers details should get visible in "Inline Lookup view" of sub-grid. From "Inline lookup view" of subgrid user can further select his desired "Lot No".

Here is my Javascript Code:

---------------------------------------------------------------------------------------------------------

function getProductsDetails() {
    debugger;
    var grid = Xrm.Page.ui.controls.get("ListLotsSubgridQuotes");
    if (grid.getVisible() == false) {
        setTimeout("getProductsDetails();", 2000);
        return;
    }
    else if (grid.getVisible() == true)
    {
        alert("grid loaded");
        var lookupObj = Xrm.Page.getAttribute("productid"); //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 Name 
                alert(lookupRecordGuid);

                var fetchXmlPL = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
                fetchXmlPL += "<entity name='new_productitemlistlots'>";
                fetchXmlPL += "<attribute name='new_name' />";
                fetchXmlPL += "<attribute name='new_vessel' />";
                fetchXmlPL += "<attribute name='new_total_estimated_cost' />";
                fetchXmlPL += "<attribute name='new_total_actual_cost' />";
                fetchXmlPL += "<attribute name='new_countryoforigin' />";
                fetchXmlPL += "<attribute name='new_brand' />";
                fetchXmlPL += "<attribute name='new_productitemlistlotsid' />";
                fetchXmlPL += "<order attribute='new_name' descending='false' />";
                fetchXmlPL += "<filter type='and'>";
                fetchXmlPL += "<condition attribute='new_productno' operator='eq' uiname='" + lookupRecordName + "' uitype='product' value='" + lookupRecordGuid + "' />";
                fetchXmlPL += "</filter>";
                fetchXmlPL += "</entity>";
                fetchXmlPL += "</fetch>";

                var viewId = "{00000000-0000-0000-0000-000000000001}";
                var entName = "new_productitemlistlots";
                var vwName = "List Lot Resources";
                var resFetch = fetchXmlPL;
                var resLayout = "<grid name='resultset' object='4230' jump='name' select='1' icon='1' preview='1'><row name='result' id='userqueryid'><cell name='name' width='300' /><cell name='ownerid' width='100' /><cell name='modifiedon' width='100' /></row></grid>";
                //Set the view using ContactsIFollow

                var ProductsIFollow = {
                    entityType: "product", // SavedQuery
                    id: "{F814628E-114D-E711-80FF-5065F38A4B41}",
                    name: "Products I Follow"
                }
                Xrm.Page.getControl("ListLotsSubgridQuotes").getViewSelector().setCurrentView(ProductsIFollow);
                grid.refresh();
            }
        }
        return;
      }
}

-------------------------------------------------------

I am not able to set FETCHXML to the sub-grid. Also not able to set custom view to the sub-grid.

Kindly help as I got stuck in this very badly.

Thanks a lots.

Regards

Kavita

*This post is locked for comments

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: assign dynamic filtered view to subgrid in Dynamics 365 online

    Kavita,

    I am not sure about "set FETCHXML to the sub-grid" but I don't think your code above"....getViewSelector().setCurrentView(ProductsIFollow);" will work....as per MS documentation, entitytype should be either '4230' or  '1039' with the valid GUID. In your case, its is set to "Product".

    Check this link for more info

    https://msdn.microsoft.com/en-us/library/dn932126.aspx#BKMK_ViewSelectorSetCurrentView

    If the subgrid control isn’t configured to display the view selector, calling this method on the ViewSelector returned by the GridControl.getViewSelector will throw an error.

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans