I've an event receiver and in itemupating i check if i've a value for a lookup field but get an exception. If i look in powershell, the column exist so the first if is ok but he can't test if it's null. I've tried to replace the space by x0020 with no more success this line is working but doesn't get the value: properties.ListItem.Fields["Service box"]

if (properties.ListItem.Fields.ContainsField("Service box"))
            //here is throw the exception
            if (properties.ListItem["Service box"] != null)
                serviceOld = properties.ListItem["Service box"].ToString();

I follow this next post without success: http://blog.vanmeeuwen-online.nl/2012/07/value-does-not-fall-within-expected.html


  • what type of column is Service box? Jul 2 '14 at 8:24
  • How many LookUp Columns are their ? Jul 2 '14 at 8:32
  • i've increase number till 50 but i've only 2 lookup Jul 2 '14 at 9:08
  • where and what you have increase till 50??? Jul 2 '14 at 9:11
  • the List View Lookup Threshold in central admin Jul 2 '14 at 13:29

you should use the itemupdating afterproperties for this:

if(properties.AfterProperties["Service box"] == null)
         //Cancel event
         properties.Cancel = true;
         properties.ErrorMessage = "value cannot be null";


its todo with the current condition of the item. Your using the event itemUpdating what means that it still hasnt saved and so doesnt exist yet.

If you did itemUpdated than you would see the changes after its saved. Thats why we have AfterProperties for itemUpdating to know what the user has put it to verifiy before its saved.

AfterProperties exist for both updating and updated and contains what the user has put in but before its saved to sharepoint.

the difference is if you use properties.listitem, than in updating it has the old values as its not saved yet but in updated it would have the same value as AfterProperties :) as its saved now so both would be the same. Thats where you would user BeforeProperties.

Gets a hash table of properties consisting of string/value pairs that correspond to fields in the SPItem object after the event occurred.

it should also note before its saved ;) too.


  • it seems working with afterproperties and in itemupdated too. Why can't i use listitem? Jul 2 '14 at 9:18
  • just updated my answer to answer your question :)
    – Ali Jafer
    Jul 2 '14 at 12:15
  • it seems in itemupdated if i get my lookup value with AfterProperties i've only the id and not id;#title Jul 2 '14 at 13:11
  • In itemupdated, AfterProperties give always to me a null value! and ListItem throw the exception Jul 2 '14 at 13:34
  • but your using item updating not updated! the code should work in item updating as you requested!
    – Ali Jafer
    Jul 2 '14 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.