Sunday, March 1, 2009

Creating a EntityEditorWithPicker with custom items

Googling around for information about the SharePoint people picker results in a couple of excellent posts that can be used for the basis of a customised EntityEditorWithPicker.

In particular: Customizing the EntityEditorWithPicker by Igor Kozlov and Customize EntityEditorWithPicker by Hrvoje Kušanić.

I needed to go one step further with my SimpleQueryControl, I needed to filter out users by only selecting those with a value set by a combobox on the page with the picker.

To do this I set the custom propery of the EntityEditorWithPicker, where AppPicker is the ApproverPickerEntityEditor and BusinessAreaPicker is the combobox:


ApproverPickerEntityEditor AppPicker = new ApproverPickerEntityEditor();
AppPicker.CustomProperty = BusinessAreaPicker.SelectedValue;


This CustomProperty is appended to the QueryString which is sent by the open-dialog client side javascript. So to access this we can examine the QueryString in the class that inherits from PickerDialog:


public class ApproverPickerDialog : PickerDialog


In the OnLoad event of this PickerDialog I inserted the following code:


protected override void OnLoad(EventArgs e)
{
ApproverQueryControl thisQC = (ApproverQueryControl)this.QueryControl;
thisQC.SelectedBusinessArea = this.Page.Request.QueryString["CustomProperty"];
base.OnLoad(e);
}


Where ApproverQueryControl is the class inheriting from SimpleQueryControl, it has a property SelectedBusinessArea which is used by the IssueQuery method to filter out users by the value selected in the BusinessAreaPicker on the form page.