0

have a strange behaviour with alerts on my sharepoint site.

I have a document library where i want to add alerts to specific users when adding,updating,deleting folders or documents. Alerts must not be triggered for a specific user.

ItemReceiver :

 public override void ItemAdded(SPItemEventProperties properties)
     {
        AlertManager manager = new AlertManager(properties.List, properties.Web);

        manager.UpdateAlerts();

        base.ItemAdded(properties);
    }

I have a method where i check if every user of a certain UsersGroup already has an alert or not. If not i add one.

The method which add alerts :

 private void CreateUserAlerts(SPUser user)
    {
        SPAlert newAlert = user.Alerts.Add();
        newAlert.Title = "AlertTitle" ;
        newAlert.AlertType = SPAlertType.List;
        newAlert.List = currentList;
        newAlert.DeliveryChannels = SPAlertDeliveryChannels.Email;
        newAlert.EventType = SPEventType.All;
        newAlert.AlertFrequency = SPAlertFrequency.Immediate;

        string userFilter = "userLoginNoTriggerALert";

        newAlert.Filter = "<Query><Neq><FieldRef Name=\"Author/New\"  /><Value type=\"Text\">" + userFilter + "</Value></Neq></Query>";

        newAlert.Update(true);
    }

For every first folder/document added the alert is triggered as if the filter isn't taken into account. But then everything work as expected after.

If anyone has an idea.

  • I'm guessing that on Folder creation the Author/New field isn't being filled in. Try an Or clause with just Author or Author/Old and a null Author/New – Choggo Oct 20 '14 at 15:39
  • Thanks for helping. But isn't the filter taken into account when the "immediate alerts" timer job is launched ? The filter seems not to be taken account on the first launch of the job once the alert is created. It works fine then. – esbeone Oct 21 '14 at 9:09
  • If that was it, post an answer explaining how it went, for future reference =] – Choggo Oct 21 '14 at 9:14
  • I'll try later today or tomorrow what you suggested, with Null and Author/(New,Old) and will post a feedback. – esbeone Oct 21 '14 at 14:29
  • Choggo i tried to use Author/Old and a null Author/New and other combinations. Sadly none of them worked – esbeone Oct 22 '14 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.