Monday 25 February 2019

Remove un-used templates from Sitecore


Hello Devs,

Currently I was working on Template clean-up tasks where we had to remove un-used/unreferenced templates from Sitecore.

While removing the templates, I faced one issue where I was not able to delete some of the templates and was getting below message:



I checked whether template is being referred somewhere using the links command and it was referring to the Standard Values of the template.






I removed the Standard Values of the Template but still no success. The reason might be it would be still referenced somewhere in Sublayouts/Base Templates/Data Source Templates etc.

If you are sure that template is not being used, Sitecore has one hidden utility which can make your life easier.


Sitecore admin page: <yoursiteurl>/sitecore/admin/dbbrowser.aspx

It displays the view of the Sitecore database. Its also very light weight as it doesn’t load the sub-items by-default. This doesn’t run the normal validations from the main content editor and allows you to delete the template without any validations.

Finally, I was able to delete templates which I was sure not being used.

Caution:  The Biggest drawback of this tool is you can’t restore deleted items as it doesn’t store it in Recycle bin.







Wednesday 26 December 2018

How to re-use same content items across multi-site Sitecore Instance


Hello Devs,

There might be a situation, or you may have come across one,

“How to re-use a same content item across multi-site in a Sitecore instance? “

Consider a scenario, lets say we have blog items which are global (i.e. used on Site X and Site Y)
Obviously, the presentation details would be different (Site X header, Site X footer, Site Y header, Site Y footer etc.)

You would be having a Blog landing page one for Site X and Site Y which would list down all the blog items with read more link which navigates to Blog detail page.

So, the ideal way would be that, if the user is on Site X and clicks the read more link from landing page it should show presentation details which are specific to Site X and vice-versa for Site Y.

As we are using the same content items across two sites, How would you handle Presentation details across Multi-Site?

Solution 1

One way would be that you create 2 Blog Detail page items one each for Site X and Site Y with Presentation detail of Site X and Site Y assign to them.

When the user is on Site X and clicks the Read more link it would show the Blog Detail page with the Presentation details of Site X and vice-versa for Site Y.

But it would require custom development. Right?

Solution 2

How about this, Sitecore OOTB provides device feature with predefined set of Rules where we can define our own custom rules click here...

Create a new Layout device for Site Y (device name = Y device) (Site X would use the default device) under : /sitecore/layout/Devices

Click Edit rule link and add the rule as shown in below image :














The rule specifies that when the current Site is Y it should use Y device to render the Presentation details.

Now navigate to the Standard values of the Item template (in our case Blog Items) and set the Site-specific Presentation details. Use Default device for Site X and Y device for Site Y.

Now when the user is on Site Y and opens the Blog Detail page via Read more link it would display Site Y specific presentation details and vice-versa for Site X.

In this way, we can re-use the same content items across multi-site Sitecore Instance.

That’s it for now!!!

Friday 30 November 2018

Create custom Solr index configuration file


Hello Devs,

If you want to create a custom Solr index file in your solution and having trouble in doing so (we too had trouble), you are at right place.

Earlier we used custom Lucene indexes in our solution but due to performance issues we decided to move all the custom indexes to SOLR (Read more about using Solr or Lucene).

If you are moving your custom Lucene indexes to Solr you would need to change few configurations to make it working.

Below I have created a custom Solr index file (e.g. employeecustomindex)

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <contentSearch>
      <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
        <indexes hint="list:AddIndex">
          <index id="employeecustomindex" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
            <param desc="name">$(id)</param>
            <param desc="folder">$(id)</param>
            <!-- This initializes index property store. Id has to be set to the index id -->
            <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />

            <configuration ref="contentSearch/indexConfigurations/employeeCustomIndexConfiguration" />

            <strategies hint="list:AddStrategy">
              <!-- NOTE: order of these controls the execution order -->
              <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/rebuildAfterFullPublish" />
              <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsync" />
              <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/remoteRebuild" />
            </strategies>

            <commitPolicyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch">
              <policies hint="list:AddCommitPolicy">
                <policy type="Sitecore.ContentSearch.TimeIntervalCommitPolicy, Sitecore.ContentSearch" />
              </policies>
            </commitPolicyExecutor>

            <locations hint="list:AddCrawler">
              <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
                <Database>web</Database>
                <Root>/sitecore/content/Home/Employee/</Root>
              </crawler>
            </locations>

          </index>
        </indexes>
      </configuration>

      <indexConfigurations>
        <employeeCustomIndexConfiguration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
          <indexAllFields>false</indexAllFields>

          <include hint="list:IncludeTemplate">
            <Employee>{AB47C5E1-000E-4DF1-B74F-0FC226FB19BB}</Employee>
          </include>

          <include hint="list:IncludeField">
            <EmployeeName>{6244D370-D460-41B6-A6D1-34040C828523}</EmployeeName>
            <EmployeeCity>{8B8BDA9E-C728-44D3-8859-204448812B3F}</EmployeeCity>
            <DoNotDisplay>{6F2DAA38-8467-43F1-85DD-5B5A14BB1719}</DoNotDisplay>
          </include>

          <exclude hint="list:ExcludeField">
            <EmployeeDOB>{E16B5AEE-3E7A-4CEB-A743-9CEB1CCE636F}</EmployeeDOB>
            <EmployeeBio>{6B50DE85-DCC3-4592-9746-6170E1657321}</EmployeeBio>
          </exclude>

          <fieldReaders ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/fieldReaders"/>
          <indexFieldStorageValueFormatter ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/indexFieldStorageValueFormatter"/>
          <indexDocumentPropertyMapper ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/indexDocumentPropertyMapper"/>
        </employeeCustomIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>


     1. First, we need to change the reference to (e.g.    contentSearch/indexConfigurations/employeeCustomIndexConfiguration).

  <configuration ref="contentSearch/indexConfigurations/employeeCustomIndexConfiguration" />

2. If we want to index only specific fields, set the indexAllFields property to false.

  <indexAllFields>false</indexAllFields>

3.  Set templates which we want to index in below configuration section.
  
   <include hint="list:IncludeTemplate">
       <Employee>{AB47C5E1-000E-4DF1-B74F-0FC226FB19BB}</Employee>
  </include>

4.  Set fields we want to add in index in our case we have 
    (Employee Name,Employee City,EmployeeDOB,EmployeeBio,DoNotDisplay) in Employee template

 <include hint="list:IncludeField">
   <EmployeeName>{6244D370-D460-41B6-A6D1-34040C828523}</EmployeeName>
   <EmployeeCity>{8B8BDA9E-C728-44D3-8859-204448812B3F}</EmployeeCity>
   <DoNotDisplay>{6F2DAA38-8467-43F1-85DD-5B5A14BB1719}</DoNotDisplay>
 </include>

   Set fields we don't want to add in index.

 <exclude hint="list:ExcludeField">
  <EmployeeDOB>{E16B5AEE-3E7A-4CEB-A743-9CEB1CCE636F}</EmployeeDOB>
  <EmployeeBio>{6B50DE85-DCC3-4592-9746-6170E1657321}</EmployeeBio>
 </exclude>

 5.  At last we need to add references for

    <fieldReaders   ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/fieldReaders"/>

    <indexFieldStorageValueFormatter    ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/indexFieldStorageValueFormatter"/>

    <indexDocumentPropertyMapper ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/indexDocumentPropertyMapper"/>  

which references to defaultSolrIndexConfiguration file.

After making all the changes restart your Solr service, re-build index and preview your index in Solr admin panel.

Happy Solr Indexing!!! 😊


Monday 6 August 2018

Sitecore Commerce 9u1 : One or more exception occurred while processing the subscribers to the ‘packageinstall:items:ended’ event


Hello Devs,

While Installing Sitecore Commerce 9 update 1, I faced below error -





This error seems to be from the Sitecore side.The log file from Sitecore showed below Stacktrace

Exception [1]: Microsoft.OData.Client.DataServiceQueryException  Message[1]: An error occurred while processing this request.  Source[1]: Sitecore.Commerce.ServiceProxy     at Sitecore.Commerce.ServiceProxy.Proxy.GetValue[T](DataServiceQuerySingle`1 query)    at Sitecore.Commerce.Engine.Connect.DataProvider.CatalogRepository.GetLanguages()    at Sitecore.Commerce.Engine.Connect.DataProvider.ReadOnlyCatalogDataProvider.GetItemVersions(ItemDefinition itemDefinition, CallContext context)    at Sitecore.Data.DataProviders.DataProvider.GetItemVersions(ItemDefinition item, CallContext context, DataProviderCollection providers)    at Sitecore.Data.DataSource.LoadVersions(ItemDefinition definition, Language language)    at Sitecore.Data.DataSource.GetVersions(ItemInformation itemInformation, Language language)    at Sitecore.Data.DataSource.GetLatestVersion(ItemInformation itemInformation, Language language)    at Sitecore.Data.DataSource.GetItemData(ID itemID, Language language, Version version) *** 

I tried to google this issue but was not able to find anything concrete. I raised this issue with Sitecore support and they provided me with few steps to resolve the issue.

1. Error that caused this exception is that sitecore can't connect to the Commerce Engine instance (Commerce Authoring). So, please ensure that this instance is up and running. 
Also check that sitecore has configured thumbprint to communicate with Commerce Authoring. You need specify certificate Thumbprint value (certificateThumbprint value of certificate which you've created before installation) in the App_Config\Include\Y.Commerce.Engine\Sitecore.Commerce.Engine.Connect.config
<certificateThumbprint> V A L U E </certificateThumbprint>

In my case it was fine.

2. The other approach is to disable index rebuild temporarily and rebuild all indexes after commerce is installed. To do it, you need to comment out this handler during installation process.

 <event name="packageinstall:items:ended">
        <handler type="Sitecore.ContentSearch.Events.PackagingEventHandler, Sitecore.ContentSearch" method="OnPackageInstallItemsEndHandler" />
</event>

It executes index rebuild after each package is installed. After commenting out this event I re-ran the installation process and was not able to see the error again.

Note : Don’t forget to Re-build indexes after the installation process is completed.

Happy Sitecore Commerce Installation!!! 😄😄😄