In a customer project i have a list, in which we import data from other sources regularly. Each time we import data, the users get an email, cause they configured themselves an alert. The alert-function is pretty good if someone else edit or update the list or its items, but in the case of an import we would like to disable the alerting for the time of import and enable it afterwords again. The import script uses a for-loop to import the items one by one.
So i would like to share my experiences with this case, cause i tried some things which did’nt work as expected.
Step #1: Disable alert for the list
I found this nice post. In this script, there a two functions. One disables the alert and the other enables it. It iterates through each alert on the SPWeb and checks if it is configured for the list in order to enable or disable this. I got it working, but i get the alert emails anyway. I guess that calling the function takes more time, so that the script in the function is executed after the loop is finished. I tried several ways, but still got the alert email.
Step #2: Disable alert at webapplication
In this case you disable of course every alert in the whole webapplication. Which means, that no one get any alerts in this time slot. This has effects on all site collections within in the webapplication. I found the script here. The result is not really helpful, cause i got after running the script again a lot of email alerts.
So what did i wrong?
Well, the scripts are running perfectly. The posts above are correct. My mistake was, that i executed the script in this pseudo way:
Disable Alerts -> Import Data -> Enable Alerts
But the timerjob for email alerts looks for items which are changed in the last two minutes. So i had to add a period of waiting time, before enabling the alerts again. So it should look like this:
Disable Alerts -> Import Data -> Wait 150 seconds -> Enable Alerts
Now it is working. After all i didn’t expect this topic to be so complicated and easy at the same time. But i hope it might help you to save some time:) Cause i didn’t think about this 2minutes frame.
Leave a Reply
You must be logged in to post a comment.