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.
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.
The results:
.