Wednesday, 15 May 2013

SP2013 Content Search webpart - Query Builder managed property issue


Requirement was to give a vertical slice on two diferent types of policies from one content type.
We need to create three search pages.
Page 1 Requirement: Get all policies 
webpart query:
     {searchboxquery} ContentType:Policy-Page-Content "Policy-TypesOWSCHCS"="HR"
Page 2 get all policies where policy type value is HR
webpart query:
     {searchboxquery} ContentType:Policy-Page-Content "Policy-TypesOWSCHCS"="HR"
Page 3 get all policies where policy type value is IT
webpart query:
     {searchboxquery} ContentType:Policy-Page-Content "Policy-TypesOWSCHCS"="IT"


Notice I had to encapsulate the managed property with Quotes! Why i am not sure. But out there if you have simmilar issues.

Friday, 22 February 2013

SharePoint 2013 Taxonomy field CSOM and jQuery

Wow what a day was yesterday! Felt like I was in an exam and running against time. Yes it was a lot of pressure to create the user News subscription model displayed in a Div. 

I have a simple list with two single line text columns username and the news channel. This list is populated by a webpart.

News Channel Subscription
Internal 1
Internal 1

Using second column from this custom list I had to do a lookup on pages library.

My immediate guess was to use jQuery with REST oData and will help me rapidly develop my script. But what do you know! when I started constructing the link 

It gave me the following error

The field 'News_x002d_Information_x002d_Type' of type 'TaxonomyFieldType' cannot be used in the query filter expression.

My next selection was to use CSOM (JavaScript) and CAML query. But I soon realised that since the column I wish to filter on, is Taxonomy column therefore I cannot use text values. Instead I had to do a lookup first in a hidden list called 'TaxonomyHiddenList' at the root site and fetch back the WSSID . 

Then using the WSSID I constructed the CAML query for Pages library. This can be seen below:

                                                     '<In><FieldRef Name=\'News_x002d_Information_x002d_Type\'  LookupId=\'TRUE\'  />'  + 
                                                      ' <Values>' + 
                                                                 <Value Type=\'Lookup\'>102</Value>'+
                                                                 <Value Type=\'Lookup\'>104</Value>'+
                                                      '</Values>'  +  
                                                     '</In></Where>' + 
var     oList    = hubSiteCtx.get_web().get_lists().getByTitle('Pages');   
collListItem   =  oList.getItems(camlQuery);
hubSiteCtx.executeQueryAsync(  Function.createDelegate(this,
this.onGetNewsPagesSucess)  , Function.createDelegate(this, this.onGetNewsPagesFailed) ); 

in above CAML query I constructed the string

                                                                 <Value Type=\'Lookup\'>102</Value>'+
                                                                 <Value Type=\'Lookup\'>104</Value>'+

after the lookup from custom list and Hidden taxonomy list

Second challenge :

The above query returned the data. All simple fields like title, name etc came back fine but the Taxonomy field was returning value = [object] when I used following statement


I tried other methods like


I could clearly see that above method was returning back lots of values for the taxonomy column but I couldn’t get to the label properties.

There isn’t much out there for this topic however after a bit of goggling I found that there is a new js library available


in SP2013. I just added the script link from 15 hive on my page and got some functions. I was only interested in label property but there are wssID , TermGuid etc also available. To get to the label property I used following:

oListItem.get_item(' News_x002d_Information_x002d ').get_label()

I hope this post will save you a bit of time and in time of pressure you can concentrate on more important things.

Happy SharePointing J would love your comments.
Alternate way:
UPDATED 27/02/2013 {
Guys , i found another method to get the label of the taxonomy field WITHOUT using Sp.Taxonomy.Js file.
Really easy
First wrap the oListItem.get_item(' News_x002d_Information_x002d ') in JSON.stringify() method like this and get an alert.
alert(JSON.stringify(oListItem.get_item(' News_x002d_Information_x002d ')))
This will display the information stored in the [object]. example:
by looking at the above image. You can see that you need to call 'Label' to get the details. Therefore just append that at the end.
oListItem.get_item(' News_x002d_Information_x002d ').Label


Omer Zubair

would like to thank the post 

for the help.

Sunday, 20 January 2013

HTML Page Layout issue

I have been fortunate enough to travel to Vegas for SharePoint Conference 2012 in November 2012. It was a long journey and was full of SharePoint content. After coming back from conference I was given a chance to implement an intranet on the new SharePoint 2013 platform. This was a new intranet sitting on dev servers in SP 2010 and the intranet did not make it to prod servers. It made perfect sense to upgrade to 2013.
View from my room.

Well I was very excited about new features it had to offer and was the selling point. Well to be honest the straight upgrade had lots of hiccups and eventually I had to reconfigure the web application all over again in new environment. L

Moving on from there I have still encountered some issues thus this blog, so that if you encounter similar issue you can try these solutions.

The intranet I was developing was mostly OOTB configuration and design principle given was to leverage ability of product in following order:

1.       Always use OOTB features to address any requirement,

2.       If OOTB doesn’t satisfy the business requirement use Java Script and CSOM.

3.       Use the .net server side code as last resort (Timer jobs, workflows, event receivers etc.)

Problem 1:

The first issue I received was that the page layout was not rendering the taxonomy field and multi-line fields while the page is in published or save mode. In order words whatever value you select in edit mode and save the page, then the page will not render the selected value.

Workaround / Resolution:

I googled the problem I found out that I was not alone some more people had the same issue without resolution. I had an idea that it might be the old 2010 (upgraded 2013) Content Type Hub. So I asked SP admin in the organisation to create a brand new Content Type Hub in 2013 environment and recreate all the site columns.

Guess what! It fixed the Taxonomy rendering issue! However the multi-line / note field still had the same issue.

To come around that I recreated the column but this time selected the column type as “Full HTML content with formatting and constraints for publishing”.

While this is not a fix, just a workaround, It might get fixed in next SharePoint 2013 service pack. Also note that this field will take up much more space in the database.

Problem 2:

The second problem I encountered was that the Date-Time field when added to the HTML page layout (using Snippet Gallery in the new Design Manager), it would not allow page to be saved and throw up and error “Are you sure you want to leave this page?”

If you select either option, then the other mandatory metadata values lose their selected information and you have to enter them again L.

As you know in SP 2013 you have to edit the HTML page and .aspx page gets generated automatically. Therefore using the design manager snippet gallery I started creating the page again.

Now you must be wondering that how was I sure it was date time field which was making this issue?


·         I got the snippet for every content type field from the snippet gallery.

·         Dropped the new field snippet on to my HTML page layout.

·         As soon as I dropped one field, I used to test the page layout by saving some dummy data.

·         I repeated these steps till I came across that it was the Expiry date and Review Date which was having some issue.

Now Since I cannot guess what is the issue in the system generated snippet? I had an idea.

<div data-name="Page Field: Expiry-Date"><!--CS: Start Page Field: Expiry-Date Snippet--><!--SPM:<%@Register Tagprefix="PageFieldDateTimeField" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>--><!--MS:<PageFieldDateTimeField:DateTimeField FieldName="f80d8fde-e7fb-4a29-8d3a-8ad6b90753a5" runat="server">--><!--PS: Start of READ-ONLY PREVIEW (do not modify)--><div align="left" class="ms-formfieldcontainer"><div class="ms-formfieldlabelcontainer" nowrap="nowrap"><span class="ms-formfieldlabel" nowrap="nowrap">Expiry-Date</span></div><div class="ms-formfieldvaluecontainer">21/01/2013</div></div><!--PE: End of READ-ONLY PREVIEW--><!--ME:</PageFieldDateTimeField:DateTimeField>--><!--CE: End Page Field: Expiry-Date Snippet-->


Workaround / Resolution:

On the snippet gallery I saw another button named “Custom ASP.NET Markup” .

When you click on this button I got an empty text box with two buttons (update & Reset) on RHS.

In the empty box I wrote the date time field as I would in old SP 2010 aspx page. i.e

<PageFieldDateTimeField:DateTimeField FieldName="Review-Date" runat="server"/>

And clicked on update button underneath. This refreshed the screen and on LHS panel I got a snippet with the following code in it.

<!--CS: Start Create Snippets From Custom ASP.NET Markup Snippet-->

<!--SPM:<PageFieldDateTimeField:DateTimeField FieldName="Review-Date" runat="server"/>-->

<!--CE: End Create Snippets From Custom ASP.NET Markup Snippet-->

Now since the snippet is not complete unless you register the namespace. So I added one line on top of snippet.

<!--SPM:<%@Register Tagprefix="PageFieldDateTimeField" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>-->

So final snippet can be seen below:

<!--CS: Start Create Snippets From Custom ASP.NET Markup Snippet-->

<!--SPM:<%@Register Tagprefix="PageFieldDateTimeField" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>-->

<!--SPM:<PageFieldDateTimeField:DateTimeField FieldName="Review-Date" runat="server"/>-->

<!--CE: End Create Snippets From Custom ASP.NET Markup Snippet-->

Last step: I added this snippet to my Page layout and tried saving a new page using this page layout. Wola! It saved and got published without any more annoying error!

I hope this workaround helps you if you are encountering the issue.

Please leave some comments if you have a better solution or would like to suggest anything better than what I have.