GetAlerts question

Jan 26, 2012 at 5:38 PM

I'm trying to work on a solution of sorts that will hopefully enumerate all the Alerts for a site collection on a single page and allow users (those with full control) to easily revoke alerts for users.

I started diving into the GetAlerts function but it seems to only respect the current site URL.  I first executed a "GetAllSubWebCollection" operation and extracted all the site URLs for the collection and in the complete function did an each function on the URLs as the WebUrl for the GetAlerts.

This doesn't seem to have any affect, I can see it iterating through all my subsites, but it only returns alerts for the top level site of the collection.  Is this a bug?  In this test I'm using build 0.6.1, but it doesn't look like GetAlerts has changed at all since 0.2.8.

Jan 26, 2012 at 6:21 PM

Do you have the code you started with? I remember researching this when trying to write my SPPostIt plugin. I seem to recall having the same results.

Jan 26, 2012 at 6:48 PM

This is what I started with, I'm trying a different apprach right now.

<script type="text/javascript">
  $(document).ready(function (){
   $("#output").append("<p>Hello world!</p>");
   $().SPServices({
     operation: "GetAllSubWebCollection",
     completefunc: function(xData, Status) {
       $(xData.responseXML).find("Webs > Web").each(function() {
        var $node = $(this);
        var currItem = $node.attr("Url");
        $().SPServices({
         operation: "GetAlerts",
         WebURL: currItem,
         completefunc: function(xData, Status) {
          console.log( xData.responseText );
         } 
       }); 
       }); 
     } 
  });
  });  
</script>
Jan 26, 2012 at 9:32 PM
Edited Jan 26, 2012 at 9:52 PM

And as a test, I did this:

$(document).ready(function (){
  	$("#output").append("<p>Hello world!</p>");
  	$().SPServices({
  		operation: "GetAllSubWebCollection",
 		completefunc: function(xData, Status) {
		    //console.log( xData.responseText );
		    $(xData.responseXML).find("Webs > Web").each(function() {
		      //var $node = $(this);
		      //console.log($node.attr("Title") + " " + $node.attr("Url") );
		      var currUrl = $(this).attr("Url");
		      $().SPServices({
		      	operation: "GetListCollection",
		      	WebUrl: currUrl,
		      	completefunc: function(xData, Status) {
				    console.log( xData.responseText );
				}
		      });
    		});
  		}
	});  
});
</script>
So I know the Url is properly getting passed into the completefunc to fetch more data. However if you try that with GetAlerts, the web url is ignored. This makes me believe:
  • there's a bug within GetAlerts
  • or GetAlerts is using a static URL
  • or GetAlerts isn't configured to use WebUrl
  • or it just isn't possible to aggregate all alerts from all lists and libraries in a site collection 
Jan 27, 2012 at 11:07 AM

Based on what I can see, I know that if you supply a webURL then it will pass it. I do believe that it is case sensitive and it is webUrl instead of WebUrl that you have in the code. If that was just a copy error then I am not sure. That's the only thing I can see right now.

Coordinator
Jan 27, 2012 at 12:46 PM

Dan's right; you've got the wrong spelling (case) for webURL. That'd do it. If webURL doesn't exist, the we use the current site.

M.

Jan 27, 2012 at 1:11 PM

Thanks, I guess I should have added a 5th option,

  • PEBCAK (aka, Eric is an idiot)
Jan 27, 2012 at 8:01 PM

Ok, I've been banging my head against the desk all day on this.  Using the below code, I can get my alerts properly now.  I'm trying to build a table row with some of the data returned to append to a table.  Then I'll be able to do some voodoo to delete the alerts, but the iuuse I'm facing is the table rows being written out have everything undefined.  I can't see what I'm doing wrong.

<script type="text/javascript">
  $(document).ready(function (){
   $().SPServices({
     operation: "GetAllSubWebCollection",
     completefunc: function(xData, Status) {
       $(xData.responseXML).find("Webs > Web").each(function() {
        var $node = $(this);
        var currItem = $node.attr("Url");
        $().SPServices({
         operation: "GetAlerts",
         webURL: currItem,
         completefunc: function(xData, Status) {
			    $(xData.responseXML).find("Alerts > Alert").each(function() {
			    		  var $Innernode = $(this);
			    		  var exist = $Innernode.attr("Id");
				          if (exist == "" )
				           {
				            //console.log("No alerts for this site");
				           }
				          else 
				           {
				            var theData = $(xData.responseXML).find("Alerts > Alert");
				            console.log(theData);
				            //var theData = $(this);
				            var theList = theData.attr("Title");
				            var theURL = theData.attr("AlertForUrl");
				            var theGUID = theData.attr("Id");
				            //var theFreak = $theData.attr("Frequency"); 
				            var Row = "<tr><td>"+theList+"</td><td>"+theURL+"</td><td>"+theGUID+"</td><tr>"//+theFreak+"</td></tr>"
				            $("#appendTo").append(Row);
				           } 
				}); //each           
          } //inner complete
 
       }); //inner SPServices Get Alerts
       }); //each
     } //outer complete
  }); //SPServices GetWebColl
  });  //doc ready
</script>

And would this be something better served as a DVWP with the web services as data sources and using joined subviews perhaps?

Coordinator
Jan 27, 2012 at 8:32 PM

This

var theData = $(xData.responseXML).find("Alerts > Alert");

is going to give you a set of items, not one item.

Try this instead:

var theData = $(this);

M.

Mar 15, 2012 at 1:00 AM

I'm watching this thread with great interest.

Coordinator
Mar 19, 2012 at 4:47 PM

Corsulian:

I'm not sure that much else is going to happen here. What are you looking for?

M.

Mar 21, 2012 at 7:27 PM

Now that I've put some thought into it, I'm not 100% sure.

I saw this a while back and thought, "could those principles be used to create an alerts dashboard?"

But an alert, I suppose, it not the same sort of "object" as a group is.

The thought was aimed at environments where setting up alerts falls more toward an admin/owner than the individual - so the owner could quickly see who has a certain alert/add others to it.

Coordinator
Mar 21, 2012 at 10:02 PM

I think you could do something along the lines of what you describe. The trick is to combine calls to the right Web Services operations so that you can flesh out your functionality.

M.

Nov 6, 2012 at 3:29 PM

Hi, I have been trying to make an alert dashboard.

I can't seem to get anywhere with GetAlerts() because all I am returned with is my own alerts.

I am instead looping through all users through /_layouts/sitesubs.aspx from an iframe. For each one storing the checkboxes into a JavaScript object and use that object to build a table that lists users and lists, and the corresponding checkboxes are appended in the right table cells. That works ok.

The idea would that be to flag the checkboxes for the alerts we want deleted, loop through them and create an array of GUIDs (conveniently stored in the checkboxes value attribute by design) which can then be supplied to DeleteAlerts().

I have gone as far as firing DeleteAlerts() and see it fail with a DeleteFailure error for all the alerts that aren't my own. Nonetheless I can delete the same alerts manually from /_layouts/sitesubs.aspx.

On the msdn page I see nothing about the method being only available to the current user. I have full control over my subsite, and SPServices webURL is set to that.

 

Any thoughts? I feel like I have wasted quite a bit of time...

 

Thank you.

 

 

 

Coordinator
Nov 7, 2012 at 1:42 PM

Vinzent:

It's always best to start a new thread rather than takcing onto an old, dead one.

I'm not clear what you are trying to do. Why not just use the /_layouts/sitesubs.aspx page to manage the alerts?

M.

Nov 8, 2012 at 1:01 PM

Hi Marc,

thank you for your reply. I have started a new thread here

 

The reason why I don't just use /_layouts/sitesubs.aspx to delete alerts is because I have over 300 alerts to delete at the moment.

Also that page is designed from the perspective of a single user managing their own alerts, while I would like to have a managment tool where I can have all alerts listed by user and list, and be able to make mass deletes if I want to - like deleting all alerts for a list.

 

Thank you for your help.

Btw, I love SPServices and I use it quite a lot. Works like a charm :)

 

vinz