OPEN TO WORK

Available for new opportunities! Let's build something amazing together.

Catalog Item Reuse Web Part doesn’t show Managed Property Values from DateTime Type

Cross-site Publishing Page Layouts
post

This post is over a year old, some of this information may be out of date.

Last week I was doing some experiments with the creation process of page layouts for a cross-site publishing site. After a couple tests with different types of data, I saw some weird behavior when using DateTime managed properties. The Catalog Item Reuse web part didn’t show the value for a managed property of DateTime type. The auto-created managed property for that DateTime field worked correctly, but my custom one didn’t.

This were the values for my auto-created managed property:

Show image DateTime Values
DateTime Values

The difference between the auto-created property and the custom property is the data type that is specified.

Show image Date Time Managed Properties
Date Time Managed Properties

Auto-created managed properties for a DateTime field are set to Text. My custom property was set to Date and Time because I also need it for filtering and sorting.

The values which these managed properties return are also very different:

  • Text value: “PublicationDateOWSDATE”:“2014-02-11T23:00:00Z”;
  • Date and Time value: “PublicationDate”:“/Date(1392159600000)/”.

After some digging in the assembly of the Catalog Item Reuse web part (Microsoft.Office.Server.Search.WebControls.CatalogItemReuseWebPart), I found that it does a parsing from a string to a DateTime. That way, you’re custom values would never be converted correctly.

private static string GetDateTimeValue(string searchData, bool dateOnly)
{
DateTime time;
string str = searchData;
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
if (DateTime.TryParse(searchData, currentCulture.DateTimeFormat, DateTimeStyles.AssumeUniversal, ref time))
{
str = dateOnly ? time.Date.ToString("D", currentCulture.DateTimeFormat) : time.ToString("f", currentCulture.DateTimeFormat);
}
return str;
}

Another downside of the catalog item reuse web part, is that you cannot define the format of your date time. You only have the option to show the time or not.

If you want to do some formatting to your DateTime values, the best option you have is to visualise it with a Content Search Web Part.

Important:: this blog post is written based upon my findings in SharePoint 2013 with the December 2013 CU installed.

Related articles

Report issues or make changes on GitHub

Found a typo or issue in this article? Visit the GitHub repository to make changes or submit a bug report.

Comments

Elio Struyf

Solutions Architect & Developer Expert

Loading...

Let's build together

Manage content in VS Code

Present from VS Code