none
Not Able to Update Alerts on List level using Client Side Object Model RRS feed

  • Question

  • Hi  ,

    I am trying to Update the Alerts associated with a SharePoint List on SPO using Client side code . I  am able to fetch all the alerts  within the list , but modifying any property of the alert is throwing me the error  "The object is not associated with an object identity or the object identity is invalid " .  My current requirement is to disable the alert while the item is updated and Re enable it again once the item update is complete. Please find below the piece of code that is in use.

     private static void ChangeAlertStatus(ClientContext contx, Guid listId, bool enable)

    {

                            

     AlertCollection alerts = contx.Web.Alerts;
     contx.Load(alerts, items => items.Include(item=> item.ID, item => item.Status, item => item.ListID, item => item.Title, item => item.Properties));
      contx.ExecuteQuery();


                    foreach (Alert alert in alerts)
                    {
                        if (alert.ListID.Equals(listId))
                        {

                            if (enable)
                                alert.Status = AlertStatus.On;  // Here i am facing the issue and Exception is thrown.
                            else
                                alert.Status = AlertStatus.Off;

                            alert.UpdateAlert();
                            contx.ExecuteQueryRetry();

    }

     If any of you have any other alternative suggestion to disable the alert functionality on a List level ( Pragmatically)  , Kindly share your valuable inputs

    Thanks in advance.

    Thursday, July 20, 2017 3:17 AM