0

SP2016 event receiver: I have a requirement that on the itemAdded event I have to get the list item id and manipulate it and then keep it in another column.

So, on the itemAdded event, I am getting the item id eg. 34 then in same event I am making it like PR_US_34 then storing it in another column name as Request no. then send an email (.net) to the user's email with the new request no. but when I am reading the request no to send in the email, its throwing null exception.

public override void ItemAdded(SPItemEventProperties properties)
{
    base.ItemAdded(properties);
    var context = SPContext.GetContext(properties.Web);
    string requestId = Convert.ToString(properties.ListItem["ID"]);
    GenerateRequestNo(properties.ListItem["ProjectLocation"].ToString(), context); //Generate Request no with some business requirement. and storing in "RequestNo" column
    string custRequestNo = properties.ListItem["RequestNo"].ToString(); // throwing null exception
    NotifyRequester(custRequestNo); // email to users new customId
}

I have tried AfterProperties as well but no luck.

1

Have GenerateRequestNo return the value that it generates and use that.

  • that's a tricky way to do that, thanks, worked for me. but could you please tell me why assigning and reading again the same column giving null exception? – Rishi Jagati Mar 13 at 13:53
  • Because properties.ListItem is an object in memory that was passed into ItemAdded. If you update the list item through some other code it's not going to magically update properties.ListItem. Inspect it with the debugger and you'd have seen this immediately. – Derek Gusoff Mar 13 at 14:00

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.