Email: info@zenconix.com

Show status messages in SharePoint

Published on: 07/30/14 3:15 PM

Category:SharePoint 2013 SP.UI Tags: ,

SP.UI Namespace

For showing Notifications and Status messages we are going to use SP.UI Namespace. Namespace provides types and members for working with the user interface in Microsoft SharePoint Foundation. This namespace includes members to work with status messages, notifications, and dialogs.

SP.UI.Status Class

This class provides methods for managing status messages.

SP.UI.Status

This provides some methods as

SP.UI.Status.addStatus(strTitle, strHTML, atBegining) Method

This method adds status message on the page

var value = SP.UI.Status.addStatus(strTitle, strHtml, atBegining);

Parameters

strTitleThe title of the status message.

strHtmlThe contents of the status message.

atBeginingSpecifies whether the status message will appear at the beginning of the list.

* where strHtml and atBegining are optional

Returns

string : The ID of the status message.

Function can be written as

function addStatus() {
    statusId = SP.UI.Status.addStatus("Hello World!");       
    }
SP.UI.Status.appendStatus(sid, strTitle, strHTML) Method

This method appends text on an existing status message.

var value = SP.UI.Status.appendStatus(sid, strTitle, strHtml);

Parameters

sid: The ID of the status message.

strTitle: The title of the status message.

strHtml: The contents of the status message

Returns

String : The ID of the status message.

SP.UI.Status.removeAllStatus(hide) Method

This method removes all status messages from the page.

SP.UI.Status.removeAllStatus(hide);

Parameters

hideSpecifies that the status messages should be hidden.

* where parameter hide is optional

Function can be written as

 function RemoveAllStatus() {
        SP.UI.Status.removeAllStatus(true);
}
SP.UI.Status.removeStatus(sid) Method

This method removes the specified status message.

 

SP.UI.Status.removeStatus(sid);

Parameter

sidThe ID of the status message to remove.

Function can be written as

 function RemoveLastStatus() {
    SP.UI.Status.removeStatus(statusId);
    statusId = ' ';
}
SP.UI.Status.setStatusPriColor(sid, strColor) Method

This method Sets the priority color of the specified status message.

 

SP.UI.Status.setStatusPriColor(sid, strColor);

Parameters

sid: The ID of the status message.

strColorThe color to set for the status message. The following table lists the values and their priority.

Value Priority
Red Very Important
Yellow Important
Green Success
Blue Information

 

Function can be written as 

  • For success status
  1.   function successStatus() {
         statusId = SP.UI.Status.addStatus("Data Save successfully!");
         SP.UI.Status.setStatusPriColor(statusId, 'green');
     }

    successStatus

    • For error/ very important status
      function errorStatus() {  
          statusId = SP.UI.Status.addStatus("Something goes wrong!");    
         SP.UI.Status.setStatusPriColor(statusId, 'red'); 
     }

    errorStatus

    • For important status
      function importantStatus() {
                  statusId = SP.UI.Status.addStatus("this is very much important!");
                  SP.UI.Status.setStatusPriColor(statusId, 'yellow'); 
        }

    importantStatus

  2. For information status
     function informationStatus() {
             statusId = SP.UI.Status.addStatus("this is information!");
              SP.UI.Status.setStatusPriColor(statusId, 'blue');
   }
importantStatus

SP.UI.Status.updateStatus(sid, strHtml) Method

This method updates the specified status message.

SP.UI.Status.updateStatus(sid, strHtml);

Parameters

sid: The ID of the status to update.

strHtml: The new status message.

 


0 thoughts on "Show status messages in SharePoint"

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Gets a username from SharePoint’s User profile service

Here is script of “How to get username from user id from Active directory”   [code language=”css”] // get user name from id function getUserFromId(userid) { // var userid = _spPageContextInfo.userId; var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")"; var requestHeaders = { "accept": "application/json;odata=verbose" }; $.ajax({ url: requestUri, async: false, contentType: "application/json;odata=verbose", […]

Get the User ID of Active Directory name in SharePoint by Javascript

How to get User Id from Site User if you have User’s active directory name [code language=”css”] //Get the id of user from AD name. function getADNameId(adName) { var UserData; $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/SiteUsers?$Select=Id,Title&$filter=Title eq ‘" + adName + "’", type: "GET", async: false, headers: { "accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose" }, success: function (data) { […]

Get selected element Id from Task List

“Very BAD practices !!!”  Sometimes situation comes that you don’t have any other options but you have to work on it and get work done. If this situation comes then you are just searching for any possible solution (many times you know that it is wrong approch to do so…).  I have come across the situation, […]