Monday, June 2, 2014

SharePoint 2010/2013 - Today as Calculated Column - Used for date age calculation

 

SharePoint does not allow the Calculated field with function like [Today] or [Me] , And when we required to calculate a age of an issue created from today's date, this will be an issue.  Here is  a simple way to fix this issue

  1. Add a new column to list with Today as Column name and select Date Time as Type.
  2. Select the default value as Today's date and save it 
  3. Create  a new column as Age and select type as calculated field. Use the below formulate to get the date difference. 
  4.         =IF([Created]="","NA",Today-[Created]) 
  5. Select the data type returned from this formula as Number and set number of decimals to 0 and save it.
  6. Now delete the Today columns that is created from step 1. ( if you don't delete this , answer will be based on this column which will be empty and you'll get a -ve value).
  7. Now your list display difference as the age in days.
Here , you can use any other date column that you have created. This formula will give you the result as difference between today and created date. EX: Created Date = 5/1 and Today is 6/2, then Age = 32.  And for custom columns if no date is present, this will display NA.


PS: The calculated fields will not auto refresh every day. For auto refresh, it has to go through custom code or timer job.

Happy Browsing!
Relax..

 

Thursday, May 29, 2014

SharePoint 2010/2013 - Notifications options



SharePoint provide OTB model dialog which can be used from client side to show a message or loading splash which you load a application page on your model dialog. Below are the options that can be used in a content editor or JavaScript file on your SharePoint page.
Add this tag to avoid null ref error ( like 'SP.UI.Notify' is null or not an object or 
Message: 'SP.UI.ModalDialog' is null or not an object).
 < script src="/_layouts/SP.UI.Dialog.js" type="text/javascript" >
or
Try adding this in code after option declaration while calling popup.
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);

To give a Loading Notification for a model dialog. 
Start of displaying the notification
var waitDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose('Working on it', 'Please wait while we load your screen...', 70, 340);
To Stop the loading Screen
waitDialog.close();
If you want to display notification in the top right corner then use this.
To Start notification
var notification;
ExecuteOrDelayUntilScriptLoaded(function () 
notification = SP.UI.Notify.addNotification("BI Charts are getting loaded!", true);
});
 // ExecuteOrDelayUntilScriptLoaded this function prevent the null ref error and it wait till the SP.UI.Dialog.js loads.
To Stop notification
SP.UI.Notify.removeNotification(notification);
---------Example-----------------------

< script type="text/ecmascript" language="ecmascript" >

var statusId = '';
var notifyId = '';

function AddNotification() {
    notifyId = SP.UI.Notify.addNotification("Hello World!", true);
}

function RemoveNotification() {
    SP.UI.Notify.removeNotification(notifyId);
    notifyId  = '';
}

function AddStatus() {
    statusId = SP.UI.Status.addStatus("Status good!");
    SP.UI.Status.setStatusPriColor(statusId, 'red');
}

function RemoveLastStatus() {
    SP.UI.Status.removeStatus(statusId);
    statusId = '';
}

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

< /script >
 
PS: Please correct the tags spacing and add js file ref.

Source: https://msdn.microsoft.com/en-us/library/office/ee658473%28v=office.14%29.aspx

Happy Browsing!
Relax..

Saturday, May 10, 2014

SharePoint 2010 - Remove Chart Webpart  Default Options Display



To hide the legends and Other information ( Data options) from the Chart Webpart, Set ShowToolbar="False" from the SharePoint Designer in XSLT mode.



Happy Browsing!
Relax..