{"id":759,"date":"2010-09-20T17:41:28","date_gmt":"2010-09-20T15:41:28","guid":{"rendered":"http:\/\/www.itidea.nl\/?p=759"},"modified":"2015-09-08T20:35:32","modified_gmt":"2015-09-08T18:35:32","slug":"simple-alert-me-option-on-a-sharepoint-page-with-spservices","status":"publish","type":"post","link":"https:\/\/www.itidea.nl\/index.php\/simple-alert-me-option-on-a-sharepoint-page-with-spservices\/","title":{"rendered":"Simple Alert Me option on a SharePoint page with SPServices"},"content":{"rendered":"<p>On SharePoint lists you can receive email notifications when items change in a list, the \u2018Alert me\u2019 function in the Actions menu of a list.<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/09\/AlertMe.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-760\" title=\"AlertMe\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/09\/AlertMe.png\" alt=\"\" width=\"264\" height=\"68\" \/><\/a><br \/>\nIn some occasions there are multiple lists where the data in it is interesting to monitor. For example values of currencies or commodities. When a webpart is used to display values of these lists to users it can be difficult for users to set the email notifications on one or more of these lists, because the user doesn\u2019t (have to) know which lists are involved.To make it all a bit user friendly I\u2019m going to give the user the possibility to easily add an email notification at the same page the webpart is displayed. The user can stay on one page to analyze some data and create a notification for the lists used (the source data lists) in the webpart.<\/p>\n<p>The webpart (not specified further here) to analyze some data uses a subset of all the lists available at the SharePoint site. The lists used are listed in another list, from now on called BaseList. So the BaseList contains all the lists (static name) used as source data.<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/09\/BaseList.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-761\" title=\"BaseList\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/09\/BaseList.png\" alt=\"\" width=\"441\" height=\"141\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/09\/BaseList.png 441w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/09\/BaseList-300x95.png 300w\" sizes=\"auto, (max-width: 441px) 100vw, 441px\" \/><\/a>\u00a0\u00a0<\/p>\n<p>Content editors can easily add other lists with data to the SharePoint site for analyzing purposes. To use these lists for analyzing purposes in the webpart they can add (or remove) that list to the BaseList. The webpart uses all the lists specified in BaseList and the users can set notifications to these lists.<\/p>\n<p>For displaying all the possible email notifications to set on the page, SPServices comes to the rescue.\u00a0\u00a0<\/p>\n<p>Because of the BaseList it is easy to determine which source data lists are involved. To set an email alert always the same default SharePoint page from the _layouts folder is used: SubNew.aspx with the listguid as parameter. If these two are combined, the solution is already there.\u00a0\u00a0<\/p>\n<p>First a function is created to retrieve all the lists from the BaseList:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 function GetAvailableLists(listName) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 counter = 0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $().SPServices({\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 operation: &quot;GetListItems&quot;,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 listName: listName,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 async: false,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CAMLViewFields: '&lt;ViewFields&gt;&lt;FieldRef\/&gt;&lt;FieldRef\/&gt;&lt;\/ViewFields&gt;',\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 completefunc: function(xData, Status) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $(xData.responseXML).find(&quot;&#x5B;nodeName= z:row]&quot;).each(function() {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 GetListId($(this).attr('ows_NameOfList'), $(this).attr('ows_DisplayNameOfList'));\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 counter += 1;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 });\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 });\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n<\/pre>\n<p>The ViewFields contains two columns of the BaseList, one for the static name of the list and one with a self made up display name. The display name will be used as text of the link generated below, the static name for retrieving the guid of the list.\u00a0\u00a0<\/p>\n<p>In the code above the function GetListId() is used:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 function GetListId(listName, displayName) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var id = &quot;&quot;;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $().SPServices({\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 operation: &quot;GetList&quot;,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0listName: listName,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 async: false,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 completefunc: function(xData, Status) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 id = $(xData.responseXML).find(&quot;List&quot;).attr(&quot;ID&quot;);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (id != null) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 items&#x5B;counter] = &quot;&lt;a href='\/_layouts\/SubNew.aspx?List=&quot; + id + &quot;&amp;Source=&quot; + returnToPage + &quot;'&gt;&quot; + displayName + &quot;&lt;\/a&gt;&quot;;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 });\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n<\/pre>\n<p>This piece of code gets the guid of the list and formats the right url for the notification. The Source parameter here is set to a returnpage. It is convenient for the user to be redirected to page he was coming from otherwise he will be redirected to the AllItems.aspx page from the list where the notification has been set. The formatted url is stored in an array, because I have another function for displaying it nicely at the page, that I\u2019m going to leave to your imagination.\u00a0\u00a0<\/p>\n<p>Copy all the code in a Content Editor webpart \u00a0and you\u2019re done.<br \/>\nThe result on the page is dependent on how you format it, but practically no more than a bunch of links, e.g.:<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/09\/AlertLinks.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-762\" title=\"AlertLinks\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/09\/AlertLinks.png\" alt=\"\" width=\"178\" height=\"40\" \/><\/a>\u00a0\u00a0<\/p>\n<p>With the link set to:\u00a0\u00a0<\/p>\n<p>http:\/\/&lt;your site&gt;\/_layouts\/SubNew.aspx?List={1FAFC5F9-F8D8-4CB6-852E-5AD4DB12CB04}&amp;Source=Default.aspx<\/p>\n","protected":false},"excerpt":{"rendered":"<p>On SharePoint lists you can receive email notifications when items change in a list, the \u2018Alert me\u2019 function in the Actions menu of a list. In some occasions there are multiple lists where the data in it is interesting to &#8230; <a class=\"more-link\" href=\"https:\/\/www.itidea.nl\/index.php\/simple-alert-me-option-on-a-sharepoint-page-with-spservices\/\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,8],"tags":[11,42,33],"class_list":["post-759","post","type-post","status-publish","format-standard","hentry","category-sharepoint-2007","category-sharepoint-2010","tag-jquery","tag-sharepoint-2010","tag-spservices"],"_links":{"self":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/759","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/comments?post=759"}],"version-history":[{"count":4,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/759\/revisions"}],"predecessor-version":[{"id":766,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/759\/revisions\/766"}],"wp:attachment":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/media?parent=759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/categories?post=759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/tags?post=759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}