In this webinar, our experts showcase a variety of demo use cases of how different components of the...
PartyList fields can be a very powerful component of activities in Dynamics CRM. Otherwise known as the Activity Party, the PartyList controls what you see in the To, From, and CC lookup fields of an activity. Sometimes you need a little more control over the UI/UX surrounding the PartyList! Currently, there is no out-of-the-box method to filter the PartyList fields in CRM 2015, so you have to utilize JavaScript instead. In today's blog, we will show you how you can filter PartyList fields using JavaScript and the addPreSearch method.
The business requirement we have today filters the PartyList field "Attendees" on a CRM appointment based on the "Regarding" field that is populated on an Account.
Specifically, we want to check the "Regarding" value on an Appointment, and apply the following filtering logic: If the value in "Regarding" is an Account, filter the "Attendees" field to only show Contacts who work at that Account as available options in the Contacts portion of Attendees.
As we mentioned before, there is no out-of-the-box method to filter the PartyList fields in CRM 2015, so we'll have to utilize JavaScript to achieve our goal instead.
The primary methods we invoke are the addPreSearch method combined with the addCustomFilter method. The actual script is fairly simple and should contain two functions. See below:
function FilterPartyList() { var Regarding = Xrm.Page.getAttribute("regardingobjectid").getValue(); //checking if regarding fields is empty before we apply the filter if (Regarding != null) { Xrm.Page.getControl("requiredattendees").addPreSearch(Filter); } } function Filter() { var RegardingValue = Xrm.Page.getAttribute("regardingobjectid").getValue(); //if Regarding has a value, proceed if (RegardingValue != null) { //used to retrieve Name of the Account held in the Regarding field var RegardingTextValue = RegardingValue[0].name; //GUID used in filter var RegardingID = RegardingValue[0].id; var plist_filter = "" + " "; Xrm.Page.getControl("optionalattendees").addCustomFilter(plist_filter, "contact"); } }" + "
Once your scripts are in libraries, add them to the Appointment entity form. In the Form Properties area, we'll need to call the scripts. We'll want to call our FilterPartyList function OnLoad of the form, and OnChange of the "Regarding" field:
Control | Event | Library | Function |
Form | OnLoad | PartyList_Filter Library | FilterPartyList |
Regarding (field) | OnChange | PartyList_Filter Library | FilterPartyList |
This can be achieved in the Form Editor, in Form Properties. Once deployed and pubished, you'll want to be sure to test out your work:
1. If an Appointment is without "Regarding" populated, no filtering will be applied to the "Required" field and the user can select Contacts/Accounts freely:
When you click the "Regarding" field above, you will see a full list of Contact records to choose from.
2. If the Appointment has the "Regarding" field populated with a Contact, the filter will be applied. As you can see in the example below, Susan Burk works at A. Datum Corp.
When you click on the "Required" field shown above, and attempt to add a Contact to the PartyList, you will be prompted with a filtered list of Contacts who work at A. Datum Corp.
That's all there is to it! Be sure to check out our blog on using the addPreSearch/addCustomFilter to a regular look-up field and subscribe so you don't miss any of our great CRM blog content. Did you know that PowerObjects offers a wide variety of education and training classes, including Boot Camps for CRM 2016? Check out all of our events today!
Happy CRM'ing!
Hello Joe
I followed you all the way to the last line where you addCustomFilter to "optionalattendees". When and where did the field "optionalattendees" come in?
I am trying to filter an attendees party list much in the same way. Contacts are attached to different accounts and I want the party list to only show contacts related to the specified account field called Client. I'm attempting to adapt your code to mine but "optionalattendees" threw me at the end. Could you clarify that for me?
Thank You,
Carlos