Reputation: 173
I have 3 entities like Member, LongList and ShortList. Both lists have many-to-many relationship with Member entity. I add Members to LongLists, and the Members can be added in multiple LongLists.
The user is going to create ShortLists from the Members of a LongList he/she would select. I can create views for filtering the Members according to their membership of a specific LongList, but I can't make this selection in user side, I can only create different views for each LongList created, which is not a good situation as LongLists are also created by users.
Is there a way to let the user decide which List's Members he/she is going to see? It has to work like, one dropdown to select the view "In Long List" and another dropdown to select which LongList.
Upvotes: 1
Views: 3783
Reputation: 1499
Short answer is you can't do this without the help of some JavaScript.
There are a few steps you need to take to fulfill this, firstly you cannot add an extra "dropdown" as such to allow the user to select a Long List to filter by. However, what you can do is add some custom views to a lookup window. So your goal would be this: On the lookup form expand the "view" picklist. We can add custom views to this using JavaScript.
Firstly, let me give you an example of how to do this custom view part. For our example I have made the following presumptions:
new_member
, new_shortlist
and new_longlist
. The JavaScript to add a custom view will look something like this:
function addCustomLonglistView(longlist) {
// Create a view id and a view name
var viewId = "{A2D479C5-53E3-4C69-ADDD-802327E67A0D}";
var viewDisplayName = longlist.New_Name + " members";
// Prepare the fetch xml for the lookup view
var fetchXml =
'<fetch mapping="logical" count="250" version="1.0">' +
'<entity name="new_member">' +
'<attribute name="new_memberid" />' +
'<attribute name="new_name" />' +
'<link-entity name="new_longlist" from="new_memberid" to="new_memberid">' +
'<filter>' +
'<condition attribute="new_longlistid" operator="eq" value="' + longlist.Id + '" />' +
'</filter>' +
'</link-entity>' +
'</entity>' +
'</fetch>';
var layoutXml = '<grid name="resultset" object="1" jump="new_name" select="1" icon="1" preview="1"><row name="result" id="new_memberid"><cell name="new_name" width="300" /></row></grid>';
Xrm.Page.getControl("new_memberfield").addCustomView(viewId, "new_member", viewDisplayName, fetchXml, layoutXml, true);
Xrm.Page.getControl("new_memberfield").setDefaultView(viewId);
}
This gets you part of the way. The missing piece is how about adding this to a button? That's a bit trickier. Thankfully I found another stackoverflow answer that should answer this for you:
How to add filtered view to Ribbon “Add Existing” button
Update from comments.
Some links on developer training and the sdk:
Upvotes: 1