Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Custom IAlertNotifyHandler gives error for deleted items!

$
0
0


I used the following to get the item Title, and other column values in order to send them in custom email

class CustomAlert1 : IAlertNotifyHandler
{
        public bool OnNotification(SPAlertHandlerParams ahp)
        {
          ....

          if (ahp.eventData[0].eventType == 4) //deleted items
          {
          if (ahp.a.AlertFrequency == SPAlertFrequency.Immediate}
          SPList list = web.Lists[ahp.a.ListID];
          SPListItem item = list.GetItemById(ahp.eventData[0].itemId);
          string itemTitle =item["Title"].ToString();
          var modified = item["Modified"];
          var modifiedby = item["Editor"];
          SPUtility.SendEmail(web, true, false, ahp.headers["to"].ToString(), web.Title, "COLUMN VALUES");
          }
       }
}

Since the item is deleted and I am trying to get the item Id using list.GetItemById(ahp.eventData[0].itemId) I get the following error. please advise on how could I get the  details of the item deleted?

Item does not exist. It may have been deleted by another user.
   at Microsoft.SharePoint.SPList.GetItemById(String strId, Int32 id, String strRootFolder, Boolean cacheRowsetAndId, String strViewFields, Boolean bDatesInUtc, Boolean bExpandQuery)
   at Microsoft.SharePoint.SPList.GetItemById(String strId, Int32 id, String strRootFolder, Boolean cacheRowsetAndId, String strViewFields, Boolean bDatesInUtc)
   at Microsoft.SharePoint.SPList.GetItemById(String strId, Int32 id, String strRootFolder, Boolean cacheRowsetAndId, String strViewFields)
   at Microsoft.SharePoint.SPList.GetItemById(Int32 id, String strRootFolder, Boolean cacheRowsetAndId, String strViewFields)
   at Microsoft.SharePoint.SPList.GetItemById(Int32 id)
   at MSFTCustomAlerts.CustomAlert1.OnNotification(SPAlertHandlerParams ahp)


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>