Ask a questionAsk a question
 

AnswerAfterProperty in ItemUpdating event

  • Thursday, November 05, 2009 5:47 PMAni Michal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,

    I override ItemAdding/ItemUpdating/ItemDeleteing events of list item. When I am updating a listitem from EditForm, AfterProperty on ItemUpdating event is return null instead of new changed values. I checked the field name, its field internal name. Same happened with BeforeProperty. I didn't know the reason why both are returing null????

    Some article giving clue about how this, but I am not able to conclude any thing.

    http://msdn.microsoft.com/en-us/library/ms463479.aspx

Answers

  • Saturday, November 07, 2009 5:29 AMAni Michal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    Thanks for reply.
    I am using field's internal name. But its not the problem.
    I got the reason of AfterProperty is null. Actually I have some hidden fields (not display on any of the form) in sharepoint list and AfterProperty will return values for the visible fields only. All other fields values are always null even we provide the field's internal name.

    And I am using "property.AfterProperty", I have typing mistake in my previous reply and sorry for that.

    • Marked As Answer byAni Michal Saturday, November 07, 2009 5:30 AM
    •  

All Replies

  • Thursday, November 05, 2009 8:39 PMAndrew Molteno Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi 
    Could you post your event handler code. The AfterProperties should contain the changed value and the properties.listitem should contain the original value in the itemupdating event. BeforeProperties will have no value.


  • Friday, November 06, 2009 4:56 AMAni Michal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I created a custom list using object model and implement a class inherited from SPItemEventReceiver. My ItemReceiver class code is as follow:

     public override void ItemUpdating(SPItemEventProperties properties) {
          try {
            base.ItemUpdating(properties);
          
     if (listItemProperties.AfterProperties[list.Fields["Col1"].InternalName] != null ) {
              //Some business logic are here       
     }
      else {
              return;
            }
          }
          catch (Exception ex) {
            properties.ErrorMessage = ex.Message;
            properties.Cancel = true;
          }
        }
    
    Here col1 is of type GUID and it always contains EmptyGuid and Control will move to else condition having return statement. I also check the same thing with title and other fields. same thing is happened.
  • Friday, November 06, 2009 6:33 AMAndrew Molteno Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi
    I suspect your field name is wrong - list.Fields["Col1"].InternalName is not returning the value you are expecting.  To test, rather hard code the field name i.e. properties.AfterProperties["name_of_field"]. Verify the fieldname is correct in the "Name" attribute in the field element in your schema.xml (use something like vsewss to generate the list definition).

    Also, why are you using listItemProperties.After.... rather than the properties.After.. , passed in as a parameter to the eventhandler?
  • Saturday, November 07, 2009 5:29 AMAni Michal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    Thanks for reply.
    I am using field's internal name. But its not the problem.
    I got the reason of AfterProperty is null. Actually I have some hidden fields (not display on any of the form) in sharepoint list and AfterProperty will return values for the visible fields only. All other fields values are always null even we provide the field's internal name.

    And I am using "property.AfterProperty", I have typing mistake in my previous reply and sorry for that.

    • Marked As Answer byAni Michal Saturday, November 07, 2009 5:30 AM
    •