SharePoint – Displaying Custom Status Messages

With SharePoint 2010 it’s much easier to display custom event & status information to a user using the Javascript Object Model. One of the new classes is the UI Status class (SP.UI.Status) which allows developers the ability to display custom “status messages” to users. These can be anything from informational messages to critical errors.


The following code displays a sample message for 5 seconds and then removes it.

<script type="text/javascript">// <
//First wait until the SP.js is loaded, otherwise the Notification won't work and a null reference exception is thrown
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
//Function to remove the status from the page
function RemoveStatus() {
SP.UI.Status.removeStatus(this.statusId);
}
//Fucntion called after sp.js is loaded.
function Initialize() {
this.statusId = SP.UI.Status.addStatus("My Title"," My Message");
SP.UI.Status.setStatusPriColor(this.statusId, "Blue");
setTimeout(RemoveStatus, 5000);
}
</script>

Messages can be displayed using the following priorities by passing the corresponding color to the SP.UI.Status.setStatusPriColor method.

Priority Color
Very Important Red
Important Yellow
Success Green
Information Blue

One thing to note when displaying multiple messages is that the highest priority will be used. For example if you display a Very Important (Red) message and then swap out to show an informational (Blue) message. The status priority color won’t update and the second message will display as Very Important (Red).

Leave a Reply