question

FrankMartin-0949 avatar image
0 Votes"
FrankMartin-0949 asked MichaelHan-MSFT commented

ItemUpdated event not firing

I have this code where only ItemAdding is firing when I add new item in the list but ItemUpdated doesn't fire. I am expecting that when new item is added then first ItemAdding fires (which is working) and then ItemUpdated is fired (which is not working).

ItemUpdated only fires after item has been created and then I manually edit record.

 public override void ItemAdding(SPItemEventProperties properties)
 {
    if (properties.ListTitle == "MyList")
    {
       base.ItemAdding(properties);
       properties.AfterProperties["Department"] = "Information Technology";
    }
 }
    
 public override void ItemUpdated(SPItemEventProperties properties)
 {
    //some code here
 }


In elements.xml file I have written following for both events but no luck. Even if I remove this line then it still doesn't work.

 <Synchronization>Synchronous</Synchronization>

Environment is SharePoint 2016. How to fix this issue?

office-sharepoint-server-development
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered MichaelHan-MSFT commented

Hi @FrankMartin-0949 ,

That's the expected behavior for event ItemAdding. For ItemAdding event, it is to handle the event when an item is adding instead of added. To make ItemUpdated to be fired, you should have an item exist in the list.

So to achieve your requirements, you should use ItemAdded instead of ItemAdding.


 public override void ItemAdded(SPItemEventProperties properties)
 {
     if (properties.ListTitle=="MyList")
     {
         properties.ListItem["Department"] = "Information Technology";
         properties.ListItem.Update();
         base.ItemAdded(properties);
    
     }
        
 }
    
 public override void ItemUpdated(SPItemEventProperties properties)
 {
    
 }


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The idea is to apply unique permission on that list item so that's why I am expecting that after ItemAdding it fires ItemUpdated so I can apply unique permission (because ItemAdding doesn't allow apply permission or so I think)

0 Votes 0 ·

Hi @FrankMartin-0949 ,

Thus you could apply unique permission in the ItemAdded event.

0 Votes 0 ·