CHUVASH.eu

CHunky Universe of Vigourous Astonishing SHarepoint :)

javascript: Alert Me on a Page

alertme-001
Recently I needed to add an Alert Me link on Pages. Alert Me is a well known SharePoint functionality for notifying users about changes in list or list items. It is availabe in OOB SharePoint as a command in Ribbon if you go to a list view:

alertme-002

When you click on this ribbon command, SharePoint opens a modal dialog and takes you to layouts page: SubNew.aspx. To open a modal dialog and load a page is not a rocket science. So a custom “Alert Me” link is doable.

As the first step I copied the html markup from the ribbon and adjusted it a little bit.

<span class="ms-cui-img-16by16 ms-cui-img-cont-float" 
   style="margin-right: 2px;">
   <img alt="" src="/_layouts/15/1033/images/formatmap16x16.png?rev=23" 
       style="top: -295px; left: -19px;margin-top: 2px;">
</span>
<a href="javascript:takana.alertMe();">Alert Me</a>

Then the javascript code which gets the List ID and Page ID is very simple because this information is there in the magic _spPageContextInfo:

var takana = window.takana || {};
takana.alertMe = function () {
    var url = String.format("{0}/{1}/SubNew.aspx?List={2}&ID={3}"
        , _spPageContextInfo.webAbsoluteUrl
        , _spPageContextInfo.layoutsUrl
        , encodeURI(_spPageContextInfo.pageListId)
        , _spPageContextInfo.pageItemId);
    OpenPopUpPage(url);
}

This code will open a modal dialog in exactly the same way as the ribbon command in OOB SharePoint and let you subscribe to changes on that page. In this code I use String.format which is available on SharePoint pages and _spPageContextInfo which has existed since SharePoint 2010 and has been extended with more useful information about the current context.

Advertisements

One response to “javascript: Alert Me on a Page

  1. Shaun David Wilkinson 2014-02-25 at 14:15

    How would I do exactly this but with a custom list instead of the site?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Вула Чăвашла

VulaCV - Чăвашла вулаттаракан сайт

Discovering SharePoint

And going crazy doing it

Bram de Jager talking Office 365, SharePoint and Azure

My view and thoughts on Productivity and more.

My programming life

and everything in between

SharePoint Development Lab by @avishnyakov

It is a good place to share some SharePoint stories and development practices.

SharePoint Dragons

Nikander & Margriet on SharePoint

RealActivity - Real-time and trustworthy

Blog site of founder, RealActivty - Paul J. Swider

Mai Omar Desouki - Avid SharePointer

Egyptian & Vodafoner - Senior SharePoint Consultant

Cameron Dwyer | Office 365, SharePoint, Outlook, OnePlace Solutions

Office 365, SharePoint, OnePlace Solutions & Life's Other Little Wonders

paul.tavares

Me and My doings!

Share SharePoint Points!!

By Mohit Vashishtha

Jimmy Janlén "Den Scrummande Konsulten"

Erfarenheter, synpunkter och raljerande om Scrum från Jimmy Janlén

SPJoel

SharePoint for everyone

SharePointRyan

Ryan Dennis is a SharePoint Solution Architect with a passion for SharePoint and PowerShell

SharePoint 2020

The Vision for a Future of Clarity

Aharoni in Unicode, ya mama

Treacle tarts for great justice

... And All That JS

JavaScript, Web Apps and SharePoint

%d bloggers like this: