How to specify in CAML elements file

Jan 13, 2012 at 5:13 PM
Edited Jan 13, 2012 at 5:14 PM

In looking at the documentation for defining a <Field></Field> in an Elements.xml file, I can't figure out how to define the FilteredLookupField.

For a regular Lookup Field, it would be specified as:

<Field ID="<GUID>" Name="<FieldName>" DisplayName="<Display Name>" Type="Lookup" List="<Lists/Listname or GUID>" ShowField="<Field to Show in dropdown>"></Field>

where the fields to enter your text are in "purple".

I assume one would replace the Type attribute with "FilteredLookupField", but how does one specify the query or view to use?  The Schema Documentation for the <Field> element specifies a Customization attribute, but doesn't show how to use.  Is this the attribute to use, or do you just specify the additional properties?

Developer
Feb 28, 2012 at 11:45 AM

In general when working with a field type for the first time don't try to build the field definition by hand. Create it using the SharePoint browser GUI then extract the xml definition using one of several techniques, eg VS Server Explorer connected to your site, or SharePoint Manager, or save site as template & save template to disk & import template into VS.

May 3, 2012 at 3:55 PM

thcase- did you figure this out? I tried as johnmcalvert said to create it via the GUI and extract the XML definition.  The field shows up in the list and on the New Item form but there is no dropdown control and if I modify the column in the list settings, none of my special column settings (List, ShowField, or Filtering) were applied.  It just defaults to looking at the Announcements list with the Folder Child count as the selected column.

Developer
May 4, 2012 at 11:01 AM
Edited May 4, 2012 at 11:03 AM

Regarding thewire's question, my prior comment is a generic approach which usually works, with this control there is a wrinkle. There is a bug/feature in the control such that a CAML-based definition only works if you supply a GUID for the List property. This is a know issue with this control, see work item 14524. Please vote for this issue if it matters to you.

If you must provide the list name not a GUID, eg because you are deploying both the source list and filtered lookup field in a wsp so list GUID is not known, then until the bug is fixed you will have to use code in a feature receiver to define the filtered lookup field. It will not work as a CAML-based definition with list name in my experience with a real client project.

Back to the original question about how to build CAML for filter query or view custom properties: Have a look at that same work item 14524, the original question includes the necessary CAML XML fragment to define them. However, also look at work item 14022, the filter query / view property along with all the custom properties do not propagate from a site column to a list field, another bug/feature.

In spite of these issues, the control works well once deployed, I have not had any issues with my client project.