Wednesday, 18 January 2017

Configure Advanced people search in SharePoint online

In a SharePoint online tenant, you can find a search center already provisioned at the URL https://<Tenant> . This search center has a page for advanced search that can be found in the pages library - "Advanced,aspx" which facilitates users to search specifically for content in advanced mode. There can be a scenario where you want to provide your users with an advanced people search interface. This is not available Out of the box. In this post, we will walk through the steps to configure advanced people search for your SP online tenant.

These configurations might also work for SharePoint 2013 on premise, however I have only tested this in SP Online.

In a nutshell we are going to perform the following steps

1) Create a new advanced search page.
2) Edit the advanced search web part on that page to remove unwanted fields.
3) Add properties relevant to people search in the advanced search drop down.
4) Make the advanced search webpart navigate to people results.
5) Links this new advanced people search page to the people search web part.

So lets start. First we check if the "Advanced Search" page layout is available when we create new pages in the site.

Navigate to the search center -> Site Settings -> Page layouts and site templates (Under look and feel section)

Add the Advanced search page layout to the available page layouts. Navigate to the pages library and create a new page with this page layout

You will see a default advanced search web part on the page. There are a few properties which are populated by default in the drop down. There are also a few controls and language filter displayed. These are for the purpose of content search but we will get rid of all that in the upcoming steps

Now edit the page and edit the advanced search webpart. From the Search Box section of web part properties, un-check the check boxes as shown below

Also, from the scopes section, un-check the languages check box.

From the Appearance section, change the title of the web part to indicate that it is an advanced people search webpart.

Apply the changes, the extra controls which we did not need are now hidden. Since the properties in the drop down box are relevant for content and not to search people, we will modify these properties and add relevant properties such as "First Name", "Last Name", "Department" etc

Edit the web part and open the properties section from the button as indicated below. It will open a dialog box and display XML text

Copy the content and paste it in your favorite text editor, Look for the <PropertyDefs> node and the <PropertyRef> node. To search for people, we should have relevant properties in the drop down box for users to search on, For this, we need to add the Managed Properties in the drop down box.

Add a new <PropertyDef> node in inside the <PropertyDefs>.

Name - This is the name of the managed property
Type - This is the type of the managed property.
DisplayName - Specify the display name of the property in drop down.

Once this is done, add a <PropertyRef> node as shown in the image below. This will be reference to the property def we just added above.

Now copy and save the content in the "Properties" section of the web part and apply the changes to the web part. Once the changes are applies, the properties drop down will display our new property

Similarly you can add more managed properties and also remove the unwanted properties by by adding or removing the <PropertyDef> and <PropertyRef> nodes as desired

My properties dropdown looks something like this after adding FirstName, LastName and Department properties.

We are almost there, Now, since the advanced search webpart by default searches for content, it navigates to "/Pages/Reuslts.aspx" page to display content results when a keyword is searched. Since we want to search for people, we will make the webpart navigate to "/Pages/PeopleResults.aspx". To do this, edit the webpart and change the Results URL property from the "Miscellaneous" section.

Now when you search on a property in the advanced search web part, the people results will be displayed.

Search result -

I could not find a property to hide the "Result Type" drop down so this must be hidden through CSS or JavaScript

But how will users navigate to your new advanced people search page ? Easy. Open your PeopleResults.aspx page from the pages library and edit the people search web part. Enable the advanced link and add the name of the new advanced people search page.

You'll see the "Advanced" link enabled on the search web part.

Hope this helps !


Saturday, 14 January 2017

Change SharePoint online site language

As a SharePoint online site administrator, you can let your users display a site in language of their choice. Changing the display language of a site involves a couple of steps, both from the site administrator and also the user.

Site collection administrator steps:
To let users of your site use different language, you can change the available languages from the Site settings. Navigate to your site -> Site settings. Under the site administration section, select "Language settings"

This will show open a page that displays a bunch of languages.

Notice the text under Alternate language(s). Users will be able to change the site language from the languages that the site administrator makes available to the user. For now, I'll select HINDI here and click OK

Now, this will not have any effect on the site. The site will still be displayed in the default language. The administrator just made the site available in Hindi. Now, as a user, if I want to see the sites in Hindi, I need to modify a property in my user profile.

User profile language preference :

From the ribbon, click on your profile picture and click on "About Me"

Select "Update Profile"

Select the below option and click on

Click on Language and Region

From the preferences, select a language and click Add.

These are the language preferences of a user. I'll move Hindi the be my preference by using the little arrows beside the language.

Click on Save and close. It will display a dialog with information. Click OK.

You will notice that your profile page is shown in the language of your preference. Now navigate to the site where we made the language Hindi available to the users.

Monday, 14 December 2015

Property promotion and Programatically Copying documents with only required fields in SharePoint 2013.

Recently I was working on a requirement to copy documents between two site collections where the source and target document library had the same content type applied to them. The approach I took was to
- Get the source document library item
- Get the target folder where the document was to be copied
- Use the SPFolder.Files.Add() to copy the document.

Fairly simple ! The only thing I had to take care of was to copy only a specified set of field values (not all fields from content type) to the target file. (This was a part of the requirement !)

There is an overload of the ADD method that allows us to pass a Hashtable which will contain the fields that we want to copy over to the target file. So for example if I want to copy "Document Id" field of a document, I'll pass the property like this

Hashtable itemProperties = new Hashtable();
itemProperties.Add ("Document Id", "<VALUE>");

Now, though I passed only the required properties through a hashtable, all the field values of the content type were being copied. After a bit of head-scratching, I figured out that this scenario was not reproducible for a ".TXT" file but only for Microsoft Office files. This was because of SharePoint property promotion. What this basically does is when a document is added to a document library, the values of the fields in the list item for the document are added to the metadata properties of the document file and since the stream of the file was used to copy the document, the properties were getting transferred with it.

The property "ParserEnabled" of Web object allows SharePoint to know whether to retain all the properties when a file is copied/downloaded-uploaded.

So to copy only the required properties, you can disable ParserEnabled property of the web, copy the document and then set it back again

But you would not want to set the ParserEnabled property to false permanently so of course you would set it back to true in the FINALLY block of your code :)

Hope this helps !

Tuesday, 3 November 2015

get_label() or .Label : Retrieve taxonomy column value using JSOM

This is going to be a short post about something I observed recently while working with Taxonomy field and JavaScript object model. While retrieving value of the Taxonomy field of a list item, we generally use the "get_label()" method.

This is the case if you have already referenced SP.Taxonomy.js in your code before fetching the list item. We generally do something like this

It is not necessary to have SP.Taxonomy.js referenced in your code in order to retrieve the Taxonomy field value. If you do not reference SP.Taxonomy.js, you need to use the ".Label" property which is returned with the list item to retrieve the label of the term.

So the next time you are tired of scratching your head trying to figure out why you are not able to retrieve the label using get_label(), check if you have referenced Taxonomy JS and use the appropriate method.

Cheers !