Lookup field, Value does not fall within the expected range

Using a Workflow to update a Lookup field in a Library in SharePoint I ran into this error:

Value does not fall within the expected range

I had no issue obtaining the value of a value from the Lookup field.

Dim sString As New SPFieldLookupValue(DirectCast(wfP.Item(“Field-R”), String))
sString= sString.LookupValue

BUT, what I failed to pay attention to was the hyphen in the field name.

Using the U2U CAML Query Builder I discovered my problem.

The real field name was Field_x002d_L

wfP.Item(“Field_x002d_L”) = New SPFieldLookupValue(1, “Value”)

…. Make sure you are updating the correct field name.

code:

spLibItem.Item(sField) = New SPFieldLookupValue(sValueID, sValue)

This entry was posted in SharePoint by Ian Hayse. Bookmark the permalink.

About Ian Hayse

SharePoint Admin. SharePoint Guy. I have been working with SharePoint nonstop for the past six years. In those six years, I've done everything from 'normal' Admin work, development, migrations, training, planning, search, workflow, InfoPath, to crazy fixing of the hands-off SharePoint databases. I'm located in Austin, TX and can always help out with small projects.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>