none
Allowing Multiple values in a lookup column

    Question

  • Hey gang,

    I'm creating custom sharepoint lists in visual studio 2010 and I have a few lookup columns I've created.  Here's an example:

    <Field ID="{16CEF265-12FA-4DA1-B1EA-2E4ADF6252BE}" Name="CMContractAction" DisplayName="Contract Action" Type="Lookup" List="Lists/ECF Actions" ShowField="Title" Indexed="TRUE" RelationshipDeleteBehavior="Restrict" Description="Contract Actions" Group="CM List Columns"  />
    I need to set the flag "Allow Multiple Values".  This is probably a dumb question or I might be blind as a bat but what is the attribute for "Allow Multiple Values"?  Thanks, Shaun
    Thursday, March 15, 2012 6:04 PM

Answers

All replies

  • Hi Shuan,

    I think all you need to change is the Type attribute to Type="LookupMulti"

    According to the SP SDK.

    • LookupMulti A Lookup field that can contain more than one value. Parent type: Lookup.

    Let me know if this is what you're after?

    Regards,

    • Proposed as answer by Balamurugan-S Thursday, March 15, 2012 6:59 PM
    • Unproposed as answer by Balamurugan-S Thursday, March 15, 2012 7:06 PM
    Thursday, March 15, 2012 6:38 PM
  • Hi shaun,

     you change your xml as below.It will solve your issue .

    <Field ID="{16CEF265-12FA-4DA1-B1EA-2E4ADF6252BE}"

    Name="CMContractAction" DisplayName="Contract Action"

    Type="LookupMulti" List="Lists/ECF Actions" ShowField="Title"

    Indexed="TRUE" RelationshipDeleteBehavior="Restrict" Description="Contract Actions"

    Group="CM List Columns" Mult="TRUE"/>



    Thursday, March 15, 2012 7:13 PM
  • Hey guys thanks for the help.  I went ahead and changed my typ to "LookupMulti" and deployed it out.  However the "Allow Multiple Values" field is greyed out.  Is there anything else i need to enable in that column i mentioned or in the column that I'm pulling the lookup values from?
    Thursday, March 15, 2012 8:02 PM
  • did you add dd below property in your field xml? Mult="TRUE"
    Thursday, March 15, 2012 9:06 PM
  • Hi Shaun,

    please note the following restrictions about Lookup field in SharePoint:

    1. You can create a relationship between lists in different websites, but you cannot set a restrictive behavior on the relationship
    2. When you create a multiple values lookup field, you cannot enforce relationship behavior, so Before setting the RelationshipDeleteBehavior property, be sure that the AllowMultipleValues property returns false (and i think this is what make the error in your code)
    3. A relationship behavior cannot be enforced if the list contains orphaned lookup fields.
      (This can occur if the lookup field's RelationshipDeleteBehavior property was previously set to None and someone deleted the item on the target list that the lookup field points to. The lookup field is thus orphaned; it contains an invalid value).

    I hope this is useful for you.

    Friday, March 16, 2012 12:09 AM
  • Yeah that fixed it.  Thanks Balamurugan!  I appreciate it.  Have a good weekend, Shaun
    Friday, March 16, 2012 3:16 PM
  • Thanks Ali.  This was part of the problem as well.  When I deployed the solution to a new SharePoint site it gave me an error about not being able to enforce a relationship behavior with a LookupMulti field.  It's working fine now.  I appreciate your help, take care.  Shaun
    Friday, March 16, 2012 3:18 PM
  • Also note that multi-valued fields can't be indexed.
    Monday, March 19, 2012 5:14 PM
  • Yeah, found that one out the hard way.  Thanks for the reply servy42!  Take care, Shaun.
    Tuesday, March 20, 2012 12:42 PM
  • Hi,

    In my case I want to restrict delete for Allow multiple values(true) in look up column. Is there anyway I can achieve it OOB.

    As if I do not check this during delete then parent will be deleted without checking if some list is using that value, which will be incorrect

    Wednesday, October 30, 2013 6:41 PM