Home > SharePoint > Lookup Field as a Site Column using CAML | SharePoint Lookup field

Lookup Field as a Site Column using CAML | SharePoint Lookup field

Its very important when you are using CAML  syntax for Lookup field to use Overwrite=”TRUE” otherwise you will be in trouble. For multi lookup field type use the following schema:

<Field
ID=”{63C4B167-F089-4A3E-8D2D-76DB12F63FFA}”
Name=”ProdTitle”
DisplayName=”Prod:Title”
Overwrite=”TRUE”
ReadOnly=”FALSE”
List=”Lists/ListName”
ShowField=”Title”
Required=”FALSE”
Type=”LookupMulti”
Mult=”TRUE”
></Field>

For lookup field type just use the following schema

<Field
ID=”{63C4B167-F089-4A3E-8D2D-76DB12F63FFA}”
Name=”ProdTitle”
DisplayName=”Prod:Title”
Overwrite=”TRUE”
ReadOnly=”FALSE”
List=”Lists/ListName”
ShowField=”Title”
Required=”FALSE”
Type=”Lookup”
></Field>

You can use the following code snippet to set value in SP list item.

Suppose hiddenValue = “1:test1;2:test2;3:test3;”

var lookupItems = new SPFieldLookupValueCollection();
var items = hiddenValue.Remove(hiddenValue.LastIndexOf(‘;’)).Split(‘;’);
lookupItems.AddRange(items.Select(item => new SPFieldLookupValue(Convert.ToInt32(item.Split(‘:’)[0]), item.Split(‘:’)[1])));

 

Advertisements
Categories: SharePoint Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: