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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Filtering sub grid base on lookup - javascript

(0) ShareShare
ReportReport
Posted on by 2,003

HI,

I have a lead from. Lead form has a field name customer(which is account entity). Account has a relationship with custom entity- Project.

Now  i have a grid on lead form of project entity. Based on customer lookup, i need to filter the grid.

For which i have wrote a code java script but it is not working as expected.

P.S. Crm version 2016 update 1.

Code snippet:

function filterProjectGridOnCustomer()
{
debugger;
//var grid =Xrm.Page.ui.controls.get('PastProjects').control;
var grid =window.parent.document.getElementById('PastProjects');
//var grid=Xrm.Page.ui.controls.get('PastProjects');
var Grid=Xrm.Page.getControl('PastProjects');
Grid=Grid.getGrid();

var lookupfield = new Array;

//Get the lookup field

lookupfield = Xrm.Page.getAttribute('customerid').getValue();

if (lookupfield != null) {

var lookupid = lookupfield[0].id;


}
else {return;}

if (grid ==null){
/*This statement is used to wait for 2 seconds and recall the function until the grid is loaded.*/
setTimeout('filterProjectGridOnCustomer()', 2000);
return;
}


var fetchXMl = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
fetchXMl +="<entity name='msdyn_project'>";
fetchXMl +="<attribute name='msdyn_projectid' />";
fetchXMl +="<attribute name='msdyn_subject' />";
fetchXMl +="<attribute name='new_totalprojectcostcr' />";
fetchXMl +="<attribute name='new_outstandingamountcr' />";
fetchXMl +="<attribute name='new_location' />";
fetchXMl +="<attribute name='new_invoicecollectedcr' />";
fetchXMl +="<attribute name='new_invoicebilledcr' />";
fetchXMl +="<link-entity name='account' from='accountid' to='msdyn_customer' alias='ad'>";
fetchXMl +="<filter type='and'>";
fetchXMl +="<condition attribute='accountid' operator='eq' uiname=' ' uitype='account' value='"+lookupid +"' />";
fetchXMl +="</filter>";
fetchXMl +="</link-entity>";
fetchXMl +="</entity>";
fetchXMl +="</fetch>";


grid.control.SetParameter("fetchXml", fetchXMl );
grid.control.refresh();

}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Filtering sub grid base on lookup - javascript

    Hello Abhishek,

    This type of requirement I would suggest to create custom HTML webresource and implement jquery easy UI or kendo grid.

    Unfortunately there is no supported way you can filter subgrid dynamically.

  • Suggested answer
    Shaminderpal Singh Profile Picture
    1,565 on at
    RE: Filtering sub grid base on lookup - javascript

    Hi Abhishek,

    Using set parameter is an unsupported way.

    I had a similar requirement to this ,we achieved it by writing retrieve multiple plugin .

    In your case follow below steps:

    1)Create a view on project entity and in filter criteria add description = 'CustomViewProject'

    2)Create a retrieve multiple plugin on pre operation of project 

    3)Obtain the query from context

    4)Check if the filter criteria contains the above condition

    4)If yes,Get the leadid from filter criteria of query and remove condition which we added in step 1

    5)Get customer lookup value using leadid 

    6)Add a filter condition in query with step 5 values

    7)Set the query to context

    When your code will execute you will get the results filtered on your lookup value.

    Hope it helps.

    -Shaminder

  • Community Member Profile Picture
    on at
    RE: Filtering sub grid base on lookup - javascript

    Am using D365 CRM and need to filter subgrid  based on a lookup value.

    Is there any supported way? without using dom.

  • Suggested answer
    BharatPremji Profile Picture
    2,485 on at
    RE: Filtering sub grid base on lookup - javascript

    Hi Abhishek,

    Have a look at this thread, it may give you some pointers:

    https://community.dynamics.com/crm/f/117/p/208890/547980#547980

    Bharat

  • Abhishek Gupta Profile Picture
    2,003 on at
    RE: Filtering sub grid base on lookup - javascript

    Hi,

    I tried all these JavaScript. Found on some blogs that these java Script was working well till CRM version 2015 update 1.

  • Suggested answer
    PS Profile Picture
    23,577 on at

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans