Don

SharePoint TODAY column in calculated fields and auto updating it

There has been much discussion around using a [TODAY]  column in SharePoint Lists since SharePoint Lists and Libraries have been around. Other than being able to use [Today] to set a DEFAULT value, users have always asked if they could use it in a calculated field. There are workarounds well documented in various threads that detail creating a field called “Today”, then creating a calculated field ([CalculatedToday]) that references the “Today” field, and finally removing the “Today” field in order to be able to use “[Today]” in a calculated field.

The question that follows is always, “how do I get the [CalculatedToday] to update every day or on a scheduled basis?” Again, there are numerous articles documented on the internet that suggest adding and removing a [Today] field and SharePoint will update all the [CalculatedToday] fields with the current Date. Administrators have created scripts and even timer jobs to do this automatically. This method [...]

Cleaner List View Boxed style using jQuery

I’m sure we’ve all customized Lists in SharePoint to create different types of views. While most of the Styles to choose from aren’t always practical, the Boxed view is an interesting view because it creates a Table along with a row of all your properties and values, for each List item. A common issue with this view is that if you have empty values, it takes up space on the screen and is too “ugly” to use. This is particularly true if your list or library is associated with many Content Types because different Content Types may not populate certain fields. There’s also that hideous column/filter bar that doesn’t seem to have any value on a view like this.

By adding the jQuery below, you can make the Boxed view much more presentable. It will not display columns that have empty values or unchecked (yes/no) values.

$(“table.ms-listviewtable tr td.ms-stylebox table tr”).each(function() {
var [...]

By |May 20th, 2014|Uncategorized|13 Comments|

Accounting for Site / Subsite regional time zone settings

Often times, you will have custom web parts or code that write date values back to lists. In many cases, time zone settings are different across an organization and using DateTime.Now is generally not recommended.

Two scenarios come to mind. #1, when a site changes its time zone to be different than the hosted servers’ time zone. #2,  if a web part was deployed across a Site Collection and used in 5 different sub-sites with 5 different regional time zone settings.

I found the best way to retrieve a date is this here:

// time zone of site
SPTimeZone siteTimeZone = SPContext.Current.Web.RegionalSettings.TimeZone;

// currentTime will contain the current date and time according to the sites’ time zone settings
DateTime currentTime =  siteTimeZone.UTCToLocalTime(DateTime.Now.ToUniversalTime());

This will give you the current time in relation to the Site Regional Settings and will account for changes to the settings.

By |May 17th, 2014|Uncategorized|0 Comments|