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 Answer 1

1

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

2
  • 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? Commented Mar 13, 2019 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. Commented Mar 13, 2019 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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