Subscribe: SharePoint SharePoint SharePoint

Saturday, February 8, 2014

Content Query Web Part Empty Data Text

In one of the sharepoint projects that i was working on , there was a content query web part which displayed articles from an Articles subsite. There was a filter on the queried data which only showed data as per a metadata term. Now this web part was present in every other subsite. So in some of the sites it showed data while in others since there was not data to be shown, an empty web part was rendered.

SharePoint 2010

Now my client wanted to show a custom  message to the user in the CQWP like :
"No Items are currently available. Please check again soon."

So in order to do this i made some changes to the "ContentQueryMain.xsl" file in :
"\Style Library\XSL Style Sheets\ContentQueryMain.xsl"

There is one template in this file which indicates an "Empty" data. It's called "OuterTemplate.Empty".
I replaced that template with my own code and it worked perfectly fine.So anytime if there was no data to be shown in the CQWP, a custom message was displayed.

The code which i used for the  "OuterTemplate.Empty" template is as follows:
 <xsl:template name="OuterTemplate.Empty">  
     <xsl:param name="EditMode" />  
     <div id="linkitem" class="item link-item">  
       No Items are currently available. Please check again soon.  
     </div>  
       <xsl:if test="$EditMode = 'True' and string-length($cbq_errortext) = 0">  
         <div class="wp-content description">  
           <xsl:value-of disable-output-escaping="yes" select="$cbq_viewemptytext" />  
         </div>  
       </xsl:if>  
   </xsl:template>  

Thursday, February 6, 2014

How to provision Managed Metadata columns in SharePoint

Once i came across a requirement from my client involving creating of a branding package for his SharePoint site in visual studio. Now in this particular package i had to add custom master pages, page layouts, css files, js files etc.

For each page layout i had to create separate content types with some site columns. These site columns too were created in visual studio.

Now one of these site columns was a metadata column i.e. a "Taxonomy Field". I did create the whole package but when i deployed it, i found that metadata columns were not connected to Term Store.

Powershell


Since this was the first time i had worked on this kind of project so was not aware that MMS Term store needs to be connected to a Taxonomy column. I could have done the same using UI, but my client wanted it to be automated.

I came across two approaches to do so. So thought of sharing those:

1. Elements.xml : In elements.xml file of the site column, we can easily specify the termsetid so that the column can connect to term set:

*Here ShowField="Term1033" is necessary field property.
NOTE: You can find the SSPID, GroupId and TermSetID from Term Store Management link in Site Settings.
 <?xml version="1.0" encoding="utf-8"?>  
 <Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
  <Field  
     ID="{99e8cfdc-3edb-4d0e-b22e-0bde0cfe8dfd}"  
     Type="TaxonomyFieldType"  
      DisplayName="LOB"  
      ShowField="Term1033"  
      EnforceUniqueValues="FALSE"  
      Group="Custom"  
      StaticName="LOB"  
      Name="LOB">  
   <Customization>  
    <ArrayOfProperty>  
     <Property>  
      <Name>SspId</Name>  
      <Value  
      xmlns:q1="http://www.w3.org/2001/XMLSchema"  
      p4:type="q4:string"  
      xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">  
       9a5c42de-abb1-489e-87df-c68c2a30c9fc  
      </Value>  
     </Property>  
     <Property>  
      <Name>GroupId</Name>  
      <Value  
      xmlns:q2="http://www.w3.org/2001/XMLSchema"  
      p4:type="q2:string"  
      xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">  
       d86f5d20-8878-4b0d-8ef2-b7a24272e5f3  
      </Value>  
     </Property>  
     <Property>  
      <Name>TermSetId</Name>  
      <Value  
      xmlns:q2="http://www.w3.org/2001/XMLSchema"  
      p4:type="q2:string"  
      xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">  
       3ff7c119-8ad1-4676-b4f0-6d5618840527  
      </Value>  
     </Property>  
     <Property>  
      <Name>AnchorId</Name>  
      <Value  
      xmlns:q3="http://www.w3.org/2001/XMLSchema"  
      p4:type="q3:string"  
      xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">  
       00000000-0000-0000-0000-000000000000  
      </Value>  
     </Property>  
    </ArrayOfProperty>  
   </Customization>  
  </Field>  
 </Elements>  

2. Powershell : If we have already deployed the solution without connecting the columns to term store and we don't not want to change anything in the package. Then we can utilize powershell to connect to the Term Store :

 $centralAdmin = Get-SPWebApplication -IncludeCentralAdministration | Where {$_.IsAdministrationWebApplication} | Get-SPSite  
 $session = new-object Microsoft.SharePoint.Taxonomy.TaxonomySession($centralAdmin)  
 $serviceApp = Get-SPServiceApplication | Where {$_.TypeName -like "*Metadata*"}  
 $termStore = $session.TermStores[$serviceApp.Name]  
 $termSet = $termStore.Groups["Department"].TermSets["IT"]  
 $site = Get-SPSite http://myWebApp/sites/mySite  
 $web = $site.RootWeb  
 $taxonomyField = $web.Fields | Where { $_.Id -eq "99e8cfdc-3edb-4d0e-b22e-0bde0cfe8dfd" }  
 $taxonomyField.SspId = $termSet.TermStore.Id  
 $taxonomyField.TermSetId = $termSet.Id  
 $taxonomyField.AllowMultipleValues = $false  
 $taxonomyField.Update();  

Make sure you specify the GUID of the site column correctly, so that it can connect to the term store.

After following any of the above approaches you can see that the column is connected to Term Store.:

Powershell

Wednesday, February 5, 2014

"Sign in as Different User" menu option is missing in SharePoint 2013

In SharePoint 2013 you might have noticed that "Sign in as different User" menu option has been removed. Microsoft has decided to discontinue this option owing to a variety of different reasons. Though to SharePoint Admins and Approvers it might seem to be a big issue.

Since in SharePoint 2010, this menu option did offer a lot of help in checking the permission levels for various groups in SharePoint sites, same thing does not hold true for SharePoint 2013.



The reasons which might have caused Microsoft to remove this option may be summarized as below:

1. There are a lot of caching problems. The cache for one user can contradict with the other one.
2. Page content might show data and content from previous logged in users.

Now there are a number of ways to use this option :

1. In the browser just  append this link to your site url : /_layouts/closeConnection.aspx?loginasanotheruser=true

2. Another permanent solution is to make changes to the welcome.ascx user control which is located at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\welcome.ascx"

Add the following code in it before this tag --> "SharePoint:MenuItemTemplate tag with id ID_RequestAccess":

 <SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser"  
 Text="<%$Resources:wss,personalactions_loginasdifferentuser%>"   
 Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>"   
 MenuGroupId="100"  Sequence="100"  UseShortId="true"  />  

After doing this do an IISREST and you should be able to see the required option :