Pages

10/16/2011

SharePoint: Create an Alert from Anywhere

 

Users typically create an alert from a list’s ribbon or an item’s dropdown or ribbon. Regardless of where they click they get directed to /_layouts/SubNew.aspx, which is the Alert creation page. (Would you have guessed that a page named SubNew was used to create alerts?) As long as you know how to setup (or copy) this URL you can create a link to create an Alert from anywhere.

In this article we will see how to:

  • Create our own links to create a new Alert
  • Add these links to pages
  • Add these links to Quick Launch
  • Display the Alert page in a dialog box

 

Alert URLs

The URL to SubNew looks like this for a list or library level alert:

http://intranet/sites/Training/_layouts/SubNew.aspx?List=%7BE7735F69%2D5542%2D4B8F%2D9426%2DD7757EAFABD9%7D&Source=http%3A%2F%2Fintranet%2Fsites%2FTraining%2FShared%2520Documents%2FForms%2FAllItems%2Easpx&IsDlg=1

And like this for an item or document level alert:

http://intranet/sites/Training/_layouts/SubNew.aspx?List={E7735F69-5542-4B8F-9426-D7757EAFABD9}&ID=1&Source=http%3A%2F%2Fintranet%2Fsites%2FTraining%2FShared%2520Documents%2FForms%2FAllItems%2Easpx&IsDlg=1

http://intranet/sites/training the path to your site
?list= The Globally Unique ID (GUID) for the list or library (See below)
&Source Optional – if provided, the user will be redirected to this page when the OK or Cancel button is clicked in the Alert page.
(Ignored with used with &IsDlg=1)
?ID= The internal ID for the list item or document (See below)
&IsDlg=1 2010 only – used to hide the navigation parts of the master page when a page is displayed as a dialog box (See below)

 

Notes:

List GUID: Each list and library in SharePoint (actually, just about every object in SharePoint) has a unique ID based on a GUID. This ID can be found in may URLs (example: List Settings or Library Settings) and can also be found by using PowerShell, the SharePoint API or tools like this or this.

SharePoint is not consistent in the formatting of a GUID. In some cases all of the letters must be lower case, in others they must be uppercase and in some it does not matter. As you can see in the two examples above, the GUID is sometimes escaped and sometimes is plain text. In the Alerts URL it does not seem to matter which form is used.

     Escaped:   %7BE7735F69%2D5542%2D4B8F%2D9426%2DD7757EAFABD9%7D

     Not escaped:   {E7735F69-5542-4B8F-9426-D7757EAFABD9}

List item ID: Every list item has a unique integer ID. This ID unique to the list and is never reused in the same list. (Add items 1, 2 and 3, then delete 2 and add one more. The new one will be 4. 2 will never be reused.) You can display the ID by simply adding the ID column to a view.

IsDlg: Setting this to 1 does not make the page display as a dialog, rather it tells the master page to hide most navigation elements. You can test this by going to just about any page other than your Home.aspx page and adding ?IsDlg=1 or &IsDlg=1 to the end of the URL.

http://intranet/sites/Training/Shared%20Documents/Forms/AllItems.aspx?IsDlg=1

See here for more about IsDlg and even how to display dialog boxes from Quick Launch.

 

Adding an Alert URL to a page

Using a SharePoint Rich Text editor (in a Wiki home page (home.aspx), a Content Editor Web Part or a Rich Text multiline column in a list) just click the Insert tab of the ribbon, click Link and paste in the URL for the Alert.

     image

 

Adding an Alert directly to HTML:

Create an anchor tag (<A>) and add the URL for the alert. Example:

<a href="http://intranet/sites/Training/_layouts/SubNew.aspx?List={E7735F69-5542-4B8F-9426-D7757EAFABD9}&ID=1&Source=http%3A%2F%2Fintranet%2Fsites%2FTraining%2FShared%2520Documents%2FForms%2FAllItems%2Easpx"> Alert me! </a>

Note: Do not include the “&IsDlg'=1” unless you will displaying the alert page as a 2010 dialog box.

 

Adding an Alert to Quick Launch (or a Links list)

Too easy… just an a new link to Quick Launch using the URL copied from the Alert page.

 

Adding an Alert to Quick Launch (or a Links list) that displays as a SharePoint 2010 dialog box

See this article for more details and examples of SharePoint 2010 dialog boxes: http://techtrainingnotes.blogspot.com/2010/12/sharepoint-opening-2010-dialog-box-from.html

You will need to combine some JavaScript for the dialog box with the Alert’s URL to create the Quick Launch link. The following must be typed as all one line! Also note the use of single quotes (‘) around the URL.

JavaScript:var options=SP.UI.$create_DialogOptions();
options.url='/sites/Training/_layouts/SubNew.aspx?List=%7BE7735F69%2D5542%2D4B8F%2D9426%2DD7757EAFABD9%7D';
options.height = 400;
void(SP.UI.ModalDialog.showModalDialog(options))

Notes:

  • Set options.url to your Alert URL, but remove the &Source= section (unless you want to send the user to a new page after creating the alert)
     
  • If the alert page is in the same site collection, set options.url to a relative address:
      relative:     /sites/Training/_layouts/SubNew.aspx?List
      absolute:  http://intranet/sites/Training/_layouts/SubNew.aspx?List
     
  • Quick Launch has a limit of 255 characters for the URL. To save space:
    • Use relative URLs
    • Do not use “&Source=” when using “&IsDlg”  (Ignored with used with &IsDlg=1)
    • Use an un-escaped version of the GUID
       
  • You can set the options.height and options.width to what ever looks best.

    image

 

The results:

    image

image

 

.

7 comments:

Nixtastic said...

Is there any easy way to remove subscriptions?

Mike Smith said...

Subscriptions?

If you want to remove alerts it can be done two ways:

1) As a user: go to the Welcome menu (name at the top right of the page), click My Settings and then click My Alerts.

2) As a Site Owner: go to Site Actions, Site Settings and in the Site Administration section click User Alerts.

Mike

Anonymous said...

Thanks, this solves my problem with users creating alerts on pages where they have view-only access. :)

Manu Singh said...

Is there a way to set alert without opening the dialog box ? I mean once a user clicks on the set alert link it should be saved with the default values. Probably through Javascript ??

Mike Smith said...

Manu,

I don't know of anyway to create an alert using CSOM or web service calls without creating custom server side code (custom web service or a custom page or web part that you can pass parameters to).

Mike

Anonymous said...

Hi Mike,

Great info, but how do you get the internal ID for the list item? I want the alert link to be on the display form of a list and want the alert to be for that item?

Thanks.

Mike Smith said...

Anonymous,

> Internal ID

I guess you are asking about dynamically getting the ID from JavaScript... the ID is in the URL to the form and can be read from the query string:

For a library:
http://yourserver/sites/yourSite/yourLibrary/Forms/EditForm.aspx?ID=123&Source=...

For a list:
http://yourserver/sites/yourSite/Lists/yourList/EditForm.aspx?ID=123&Source=...

The ID can also be extracted from the <form> element on the page:
<form method="post" action="./DispForm.aspx?ID=123...

Mike

Post a Comment

Note to spammers...
Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.