Monday, 29 December 2014

Crawled properties not created for managed metadata field / Naming convention for note field associated with managed metadata column

 Hi again, today new problem and solution J and I feel this is very important one J

Background: In SharePoint 2013 when full crawl happens, Site Columns those have data for them managed and crawled properties are created automatically. For site column of type Taxonomy, SharePoint creates two types of crawled properties.

Consider my taxonomy field name is MyTaxonomyField and there is respective associated hidden Note field. In this case after full crawl SharePoint will create two crawled properties as
ows_taxid_MyTaxonomyField and
ows_MyTaxonomyField

First crawled property (ows_taxid_MyTaxonomyField) is mapped with automatically created managed property owstaxidMyTaxonomyField. This managed property we should use everywhere in our queries in Content Search web part or in Search Result web part  since it contains the Term Id and we can query based on Term Ids.
For second crawled property (ows_MyTaxonomyField), managed property is not created automatically. We can create our own custom managed property and map with this crawled property. But then this is not the best practice, we couldn’t query based on Term Ids since this property contains only Term Names and not the Ids. There might be possibility of having the special characters in term names like “-“. Some of these special characters have different meaning in Search (KQL) and which may cause the search queries failure or no result.

Problem: In our project, for our Taxonomy fields first crawled properties (ows_taxid_MyTaxonomyField) is not getting created and hence no automatically created respective managed property. We have only second crawled property (ows_MyTaxonomyField) created but we don’t want to use it. In our Content Search web part we want to do the query based on TermIds.

Solution:

We have following taxonomy field, here I kept only important attributes for the field others are removed:

<Field ID="{}"
         Type="Note"

         DisplayName="MyTaxonomyField _0"

         StaticName="MyTaxonomyField0"

         Name="MyTaxonomyField0"
  </Field>

  <Field ID="{}"
         Name=" MyTaxonomyField "

         Type="TaxonomyFieldType"

         DisplayName=" MyTaxonomyField "

         StaticName="MyTaxonomyField ">
  </Field>

First field is hidden Note field and second managed metadata field. Through feature receiver we are associating the Note field with Taxonomy field.
After digging / googling a lot it found that problem is in the naming convention of Note field. Note field associated with managed metadata field should contain the “TaxHTField” in its static name / Name.

So field should be like this
<Field ID="{}"
         Type="Note"

         DisplayName="MyTaxonomyField _0"

         StaticName="MyTaxonomyFieldTaxHTField0"

         Name="MyTaxonomyFieldTaxHTField0"
  </Field>

This is strange behaviour but it worked for our managed metadata fields. We spend lot of time in finding this, hopefully if same problem occurs it will save your time J
 
Thanks!
Enjoy Reading J

Feel free to comment / suggestion / feedback if any J

Friday, 26 December 2014

Usage analytics reports options (“Most Popular Items” and “Most Popular Trends”) are not available on Post or other lists

Hi Again,

Today new interesting and my favourite feature related issue and solutionJ. Our customer has reported the issue like they couldn’t see usage analytics reports options “Most Popular Items”, “Popularity Trends” for their post list. Like 

 
These are the two types of Usage analytics reports which SharePoint 2013 creates.

So we started investigation and first point to check is whether site collection level “Reporting” feature is activated or not.



“Reporting” feature is activated on site collection level. Also when we saw “Pages” library or “Document Libraries” these options are available. But not available for “Posts” list or some other lists in the site.

After googling bit in MS article “View usage reports in SharePoint Server 2013 (http://technet.microsoft.com/en-us/library/jj715890(v=office.15).aspx )” it is mentioned that “Usage reports are only available for Usage reports are only available for Document Libraries and Product Catalog lists”.

Now, it’s clear that why these options are available only for “Pages” and “Document Libraries”. But our customer wants these options for “Post” list so one of the possible options is to activate the site collection level “Cross Site Publishing” feature.


But as soon as we activate this feature, “Catlogs Settings” one extra option under List/Library settings becomes available for all the lists and libraries in the Site collection.


From this “Catalog Settings” page we can actually enable list / library as a catalog.
 

Interestingly “Cross Site Publishing” feature is dependent on “Reporting” feature. If you try to activate the “Cross Site Publishing” feature without “Reporting” feature you will get feature dependency error as

Site
The feature being activated is a Site Collection scoped feature which has a dependency on a Site Collection scoped feature which has not been activated. Please activate the following feature before trying again: Reporting 7094bd89-2cfe-490a-8c7e-fbace37b4a34

Once we have activated the “Cross Site Publishing” feature for all the lists we could see the usage analytics reports options J
Thanks!

Enjoy Reading J
Feel free to contact in case if you have any query / feedback / suggestions J
 

Wednesday, 24 December 2014

Office 365: Exception while activating publishing feature - Feature with Id ' ' is not installed in this farm, and cannot be added to this scope.

Hi All,

It’s again long time, busy with project, but continued on office 365 side. Sharing one small finding but could save your timeJ.

One of our requirements is to activate the publishing feature (“SharePoint Server Publishing Infrastructure”) on our one of the site collection which is of type Team site.
 

So we have CSOM + PowerShell approach and used following CSOM code to activate the features using PowerShell script

#getting all site features

$siteFeatures = $clientContext.Site.Features
$clientContext.Load($siteFeatures)
$clientContext.ExecuteQuery()

#activating “SharePoint Server Publishing Infrastructure” feature

$featureId = “f6924d36-2fa8-4f0b-b16d-06b7250180fa”
$fId = [GUID]$featureId
$siteFeatures.Add($fId, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::Site)
$clientContext.ExecuteQuery()

As soon as above code executed we got the following error

An error occurred activating Feature. Error detail: Exception calling "ExecuteQuery" with "0" argument(s): "Feature with Id 'f6924d36-2fa8-4f0b-b16d-06b7250180fa' is not installed in this farm, and cannot be added to this scope.”


After digging a lot and went through couple of blogs, noticed that, in some blogs FeatureDefinitionScope is set to None. We tried this option and it worked like charmJ.

So it looks like as

$siteFeatures.Add($fId, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)

For now I am not sure is this bug or it works in this way but I really wondered why so this since there are 4 scopes in FeatureDefinitionScope enumeration as


using System;
namespace
 Microsoft.SharePoint.Client
{
    public enum
 FeatureDefinitionScope
    {
        None,
        Farm,
        Site,
        Web
    }
}


I then tried with the web level feature but same error and then it worked with None option.

Summary:


While activating feature using CSOM it doesn’t accept respective scope (Site or Web), we need to provide feature definition scope as None.Thanks!

Enjoy reading :)

Feel free to comment / feedback if any :)


 


Tuesday, 16 September 2014

Adding a web part page to Office 365 team site library using CSOM + PowerShell


Hi All,

Next step towards Office 365 development is uploading /adding a web part page in “SitePages” library of team site. The site is not publishing site so we couldn’t like upload the empty page and then apply PageLayout.


So we will require a local copy of page having appropriate zones. Example of page (default.aspx) structure (this page is just for reference J):

Fig 1. Sample Page
Following are the steps and script:


1.    Get the Microsoft.SharePoint.Client.ClientContext instance


2.    Get the Web instance


3.    Get the “Site Pages” library


4.    Get the root folder and files collection


5.    For adding file, we need to create instance of Microsoft.SharePoint.Client.FileCreationInformation. Set the properties of this instance like FileUrl, FileContent etc.
 
      6.  Use the Add () method of files collection.

 Script:


#Variables which we are used below


             $LayoutPath = “c:\default.aspx”

$PagesLibraryTitle = “Site Pages”

$FileNameWithExtention = “default.aspx”

# All the above variables can be parameterised


#Password to connect the Office 365 site

            $securePassword = ConvertTo-SecureString -String $Password -AsPlainText –Force

#instance of Client Context

[Microsoft.SharePoint.Client.ClientContext]$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)

            $clientContext.Credentials = New-Object    
           Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $securePassword)

#here assuming we are adding file to root web of site collection

$site = $clientContext.Site
          $web = $site.RootWeb

$clientContext.Load($web)
$clientContext.ExecuteQuery()

#List Collection

$lists = $web.Lists

$clientContext.Load($lists)
            $clientContext.ExecuteQuery()


#Get the list

$list = $lists.GetByTitle($PagesLibraryTitle)

$clientContext.Load($list)

          $clientContext.ExecuteQuery()


#Files Collection

$files = $list.RootFolder.Files

$clientContext.Load($files)
          $clientContext.ExecuteQuery()


#instance of FileCreationInformation
[Microsoft.SharePoint.Client.FileCreationInformation]$fileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation

            #Get the file content
            $fileContent = Get-Content $LayoutPath
  
#convert the file content into Byte[] and set it to Content property of FileCreationInfo class

$fileCreationInfo.Content = [System.Text.Encoding]::UTF8.GetBytes($fileContent)
            $fileCreationInfo.Url = $FileNameWithExtention #(default.aspx)


#add the file

$page = $files.Add($fileCreationInfo)
            $clientContext.ExecuteQuery()

Thanks!

Enjoy Reading :)

Feel free to comment / feedback / suggestions / thoughts if any or if you have any query :)