Maximum before and after current page properties in SharePoint 2013 search

If you have used or worked with SharePoint search, you must have come across the pagination control that appears in the bottom of the search results web part in the search results page.

clip_image001

This control came as a separate web part in SP 2010 where we had the below 2 properties in the tool pane that can be set to show the maximum no. of page links to be shown before the current page and the maximum no. of links to be shown after the current page.

clip_image002

Whereas in SP 2013 the pagination has become a part of the core search results web part itself and is being created in the control template of the web part (more on that later). And the above 2 properties of the pagination are not seen in the tool pane of the search results web part which came as a surprise to me.

Later, to my surprise when I exported the search results web part I was able to see the 2 properties in the .webpart file as shown below:

PaginationProp

Setting the properties in the .webpart file and importing it back to SharePoint made the necessary changes in the pagination reflecting. Hope you find it useful.

Advertisements

Content search web part for a specific SharePoint list\library

This is supposed to be my first blog post on SharePoint 2013. This is about the new and the much spoken about Content search web part in SharePoint 2013. While I was working on it, I wanted to load the list items from a particular library in the content search web part. I could not find much help by googling on how to configure the query builder of the CSWP to target a specific SharePoint library.

You may also like to have a look at the below blog posts regarding Content Search Web Parts:

In this post I will explain how to target a particular library as well as a list in a CSWP by modifying its query through various options.

a. Add a CSWP to your page and edit the web part to view its tool pane. In the tool pane of the web part click on Change query to open the query builder modal window as shown below:

clip_image001

b. As you see in the above screen shot, the default configuration in the query builder is to show the recently edited items in the current site.

c. In order to display the list items from a library, select “Documents” from Select a query and select “Specify a URL” from Restrict by app and enter the URL of your library in the text that appears immediately below the drop down as shown in the below screenshot.

clip_image003

Note: While entering the URL of the library, please note that the URL should not have any “%20” in it and the URL should only be up to the library’s name. For e.g. if the URL of the library is: http://sharepointsite.com/My%20Aricles/Forms/AllItems.aspx, please change it to http://sharepointsite.com/My Aricles/ while entering.

Once you finish, the results would be shown in the Search result preview.

d. Click OK and you should see your web part displaying the document links from the document library in your CSWP.

Now let us see how to accomplish the same requirement for a list.

a. In the same web part, follow the same procedure to edit the query builder of the web part.

b. Replace the URL of the library with your list URL. You should be seeing that no results are returned in the Search result preview section.

c. Click on “Switch to Advanced mode”, you should be seeing the below screen:

clip_image005

d. As you see in the query text textbox, the file extensions of the results are being queried which restricts the results to documents alone and avoids list items.

e. Remove the text that checks for file extensions as shown below:

clip_image0072

f. Now click on “Test query” and you should see the list items from the SharePoint list returned.

jQCalendarBlog – Mini SharePoint calendar web part for SharePoint blog posts

Introduction:

This is my 2nd SharePoint client side web part application that I have developed using JavaScript\jQuery.  You can find the first application that I had created over here. This application is to integrate the published dates of the approved posts in a SharePoint Blog site with the jQuery calendar control.

Description:

This is a JavaScript application developed using jQuery. The JS code when added to a Content editor web part in a SharePoint page, it would display a jQuery calendar control synchronized with the SharePoint blog posts dates. Below are the lists of features:

  1. The calender control highlights the dates during which approved blog posts were published in the SharePoint blog site.
  2. The dates when hovered would display a small pop-up listing down link to the corresponding date’s blog posts that were published.
  3. The links when clicked would take you to the respective blog post’s page.
  4. You can also navigate to the previous and next month in the calendar to see the corresponding month’s data in a similar way as explained above.

Look at the below image for a better understanding:

As you can see in the above image, cells 1, 6, and 31 are highlighted with a blue color border to show that these are the dates in the current month having blog posts published. Also when you hover over date ‘6’ in the calendar you can see that a pop-up is being shown displaying the links to the posts published on that particular date.

Code:

I have used the jQuery DatePicker  control and SharePoint list web service to get this application done. I have tested this in an Office 365 SharePoint 2013 preview site and it works fine too. But I wanted to develop it as an app and publish it in the app store for SharePoint 2013. So please wait until I get a SharePoint 2013 development environment.

Deployment Process:

Since it is purely a client side application, we can simply deploy it by just moving the files. I assume that you have worked with CEWP before. I have explained the deployment process through the below steps:

  1. Download the  jQCalendarBlog.zip file from here.
  2. Unzip the jQCalendarBlog.zip file
  3. Copy the unzipped jQCalendarBlog folder in to the layouts folder of SharePoint server.
  4. Create a Content Editor Web Part anywhere in your SharePoint Blog site where you want to display this web part.
  5. Open the jQCalendarBlog.min.js file from the jQCalendarBlog folder and copy the content in to the CEWP created above.
  6. Save the page to see the web part showing a jQuery calendar control synchronized with the blog posts in your blog site.

SharePoint Caveat – BeforeProperties in SharePoint workflow

I had to develop an application to track the status of delivery of an order whose details would be stored in a list. To accomplish this I had to choose either an event receiver or a workflow. I chose workflows since workflows would give me a better development environment with visual representation of the flow of process using which I can do the changes so easily which is not possible with event receivers.

Of course I chose to go ahead with Visual Studio workflow rather than SharePoint designer workflow due to the recursive process involved in the requirement.

I started my development and was so happy with the way it was progressing until I faced with a hurdle which led me to stop developing the workflow and instead start with an event receiver from scratch. I was really disappointed with that.

The requirement was to compare the values of a certain field before and after the list item has been updated. This can be achieved by creating 2 workflow properties to store the after properties and before properties of the list item.

The problem was when I found that BeforeProperties was always null in the ItemUpdated event activity and only the AfterProperties had values in it. I wondered why it is null always. When I tried the same workflow for a document library instead, I found that both BeforeProperties and AfterProperties to be holding values and were not null.

After googling I found that workflows for lists have the same limitation as that of event receivers for lists. And that is finding null value in the BeforeProperties for a list item in an ItemUpdated event receiver in a list. This limitation is present in both event receiver and workflow when attached to a SharePoint list. But you can overcome this limitation in an event receiver by replacing Item Updated event receiver with an Item Updating event receiver. In an Item updating event receiver you can find values in the BeforeProperties of the item that is getting updated. You can more about it over here. But in a workflow attached to a list there is no work around which means workflow is not going to be of much use for a list in this case.

Auto Suggestion/Auto Complete for SharePoint 2010 Search sites

Introduction:

It will be very useful for the users to have the search being suggested based on the past searches while they are typing in the search text box in a SharePoint search site. Yes I’m talking about the same concept that you find in the Google search but with a limited functionality.

This feature is available as an OOTB feature in SharePoint 2013 enterprise search. Look at this link to know more about this cool feature. The process is completely different though.

Description:

This is a simple JavaScript application which when added to a Content editor web part in home page and in the search results page of your SharePoint search site would display suggestions for the users as they type their search query in the search text box. The suggestion keywords are stored and retrieved from a SharePoint custom list called “Search Keywords”. Look at the below screenshot for a better understanding:

As you can see in the above image, as I type “I love s”, I get “I love SharePoint” and “I love Silverlight” as suggestions. These 2 are retrieved from a SharePoint list called “Search Keywords”.

So how and when are these suggestion keywords stored in the “Search Keywords” list? When a user is searching in the search site and the results page finished loading, the JS code added in the CEWP in the results page would add the search query in the “Search Keywords” list as new list item. Thus the matching suggestion keywords are retrieved from the list as the user is typing in the search text box later.

Limitations:

Since the suggestion keywords are added to a SharePoint list as a new list item every time a user searches, the performance may reduce when 1000’s of items get stored in the list. So it is advised to manually delete few keywords often from the list.

Code:

The code is developed using JavaScript, jQuery, Autocomplete jQuery ui widget, and SharePoint Client object model. There are 2 different JavaScript codes. One is for the search home page and the other is for the search results page.

I have explained the code in two parts in the below blog posts:

Part 1: How to give the Auto suggestion/complete functionality to the Search box with search terms retrieved from a SharePoint list.

Part 2: How to store the users’ searched queries to a SharePoint list dynamically and then show them as suggestions in the search box while searching.

Since it is purely a client side application, we can simply deploy it by just moving the files. I assume that you have worked with Content editor web part before. You need to create 2 CEWPs, one for search home page and the other for the search results page. I have explained the deployment process through the below steps:

Deployment process:

  1. Download the SPAutosuggestion.zip file and unzip it.
  2.  Create a folder called SPAutosuggestion under the layouts folder of your SharePoint server.
  3. Copy the files jquery-1.7.js, jquery.ui.autocomplete.js, jquery.ui.core.js, jquery.ui.complete.js, jquery.ui.widget.js, and jquery-ui.CSS from the unzipped folder in to the above create folder.
  4. Go to your SharePoint search site and create a list called “Search Keywords”
  5. Go the search home page and edit the page.
  6. Add a Content editor web part in to the page.
  7. Click on “Click here to add new content” as shown in the below image:  
  8. Now in the ribbon control click on HTML -> Edit HTML Source as shown below:  
  9. In the HTML source editor window copy the content of the AutoSuggectionLandPage.js which would be present in the folder unzipped in step 1.
  10. Click on “Save & Close” under the page tab in the top ribbon.
  11. Go to the search results page of you SharePoint site and edit it.
  12. Repeat step 6 to 10. But instead of copying the content of AutoSuggectionLandPage.js, copy the content of AutoSuggestionResultsPage.js.
  13. Search with different queries twice or thrice to see them getting suggested as you type in the search text box.

jQCalendarPart – Mini SharePoint calendar web part

Introduction: This application is to integrate the jQuery Calendar control with the events added in a SharePoint Calendar list. This would work in both SharePoint 2010 and SharePoint 2013. This is a JavaScript application developed using jQuery. The JS code when added to Content editor web part in a SharePoint page, would display a jQuery calendar control synchronized with the SharePoint calendar list. Below are the lists of features:

  • The calendar control highlights the dates of all the events of the current month present in the Calendar list of the site.
  • The dates when hovered over with the mouse, would display a small pop-up showing the respective date’s events.
  • The links when clicked would open the respective event’s view form page.
  • You can also navigate to previous and next and months to view the respective months’ events.

Look at the below image for a better understanding: jQCalendarPart As you can see in the above image, cells 8, 9, 12, 13, and 14 are highlighted with a blue color border to show that these are the dates in the current month having events registered in the Calendar list. Also when you hover over date “13” in the calendar you can see that a pop-up is being shown displaying the events of that particular date. Deployment:

  1. Go to your SharePoint site and create a document library called “jQCalendarPart”.
  2. Download the jQCalendarPart.zip file from here and unzip it.
  3. Copy the files and folders from the unzipped jQCalendarPart folder in to the above created library.
  4. Create a Content Editor Web Part in your SharePoint site where you want to display this web part.
  5. Edit the CEWP and link it to the JS file called jQCalendarPart.js that was uploaded in the jQCalendarPart document
  6. Save the page to see the web part showing a jQuery calendar control synchronized with the SharePoint calendar events from the Calendar list in your site.

if you do not see the calendar control or the calendar control is not showing any events from the  calendar list, please read the caveat points mentioned in the below section. Caveats:

  1. The code has been written to retrieve events only from a calendar type list whose title is “Calendar”. If you want to retrieve from a different calendar list, please change the value of the variable “listName” from the code.
  2. All the external JS files that are used are referred using their relative URL, so if your site URL comes after “/sites”, please change the reference URLs for all the JS files that are present in the top of the code.

Code: I have used the jQuery DatePicker  control and SPServices to get this application done. I have tested this in an Office 365 SharePoint 2013 preview site and it works fine too. But I wanted to develop it as an app and publish it in the app store for SharePoint 2013. So please wait until I get a SharePoint 2013 development environment. Kindly mail me at s.c.vinod@gmail.com if you have any doubts or issues or you can also post a comment in my blog.