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

Notifications

Announcements

No record found.

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
    PS Profile Picture
    23,577 on at
  • Abhishek Gupta Profile Picture
    2,003 on at

    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
    BharatPremji Profile Picture
    2,485 on at

    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

  • Community Member Profile Picture
    on at

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

    Is there any supported way? without using dom.

  • Suggested answer
    Shaminderpal Singh Profile Picture
    1,565 on at

    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

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

    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.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans