Monday 27 June 2016

Sitecore default workflow not getting set when creating item programmatically


This was a weird issue which we faced today.  We were creating few sitecore items programmatically from an RSS feed. The Sitecore items were using press release template and we had assigned default workflow in standard values of the template.

But the programmatically created items  were not getting workflow and workflow state from default workflow set for that item. It was coming  empty. However it was working fine when we were creating an item manually. Lastly we had to set the workflow  programmatically using below code. This code will get the default workflow from item and set the workflow and workflow state.




           string defaultWorkFlowId = feedItem["__Default workflow"];
                    feedItem["__Workflow"] = defaultWorkFlowId;
                    feedItem["__Workflow state"] = GetDraftStateOfWorkflow(defaultWorkFlowId);
                 

Here is the function which is getting called

   private static string GetDraftStateOfWorkflow(string defaultWorkFlowItemId)
        {
            try
            {
                Sitecore.Data.ID workflowId = new ID(defaultWorkFlowItemId);
                Sitecore.Data.Database master = Sitecore.Data.Database.GetDatabase("master");
                if (!workflowId.IsNull)
                {
                    Item workFlowitem = master.GetItem(workflowId);
                    Item draftItem = workFlowitem.HasChildren?workFlowitem.Children.First(i => i.Name.ToLower() == "draft"):null;
                    if (draftItem != null)
                    {
                        return draftItem.ID.ToString();
                    }
                    else
                    {
                        return string.Empty;
                    }
                }
                else
                {
                    return string.Empty;
                }
            }
            catch(Exception)
            {
                return string.Empty;
            }
        }
   

Happy Automation :)

Sunday 26 June 2016

Upgrading Sitecore Lucene indexes to Coveo

Recently we updated the Sitecore_master_index to use coveo instead of Lucene. Below are the simple steps which you can follow for this upgrade, you can follow the same steps to replace any Lucene index with Coveo.


1. Replace <index id="Sitecore_master_index" /> node in Sitecore.ContentSearch.Lucene.Index.Master.config by <index id="Coveo_master_index" />  </index> node from Coveo.SearchProvider.config.

2. Change back the index id to "Sitecore_master_index" in  Sitecore.ContentSearch.Lucene.Index.Master.config.

3. This step you have to do only for releases before December 2015 (Please do not do it for after December 2015 releases you will not see Sitecore_master_index in indexing manager if you do this for after december 2015 releases) . Change your Configuration node type attribute.

<configuration type="Coveo.SearchProvider.Configuration.CoveoSearchConfiguration,
 Coveo.SearchProvider">

4. Delete "Sitecore_master_index" from your data/indexes folder and do 
reindexing for"Sitecore_master_index".If you are able to see "Sitecore_master_index" in
 indexing manager and it is getting indexed then we are good :) :)

Have a good day :)


Thursday 23 June 2016

Enable Scripting in Sitecore Rich Text editor RTE

To enable scripting in Sitecore RTE , you can change the below settings.

 <!--  HTML EDITOR REMOVE SCRIPTS
            If true, the rich text editor removes script tags and inline scripts from RTE field values before saving. Setting the value to true reduces the potential for cross-site scripting and other script-related issues.
            Default value: true
      -->
      <setting name="HtmlEditor.RemoveScripts" value="false" />
     

Sitecore rich text editor avoid generating <p> tags while pressing enter

By Default when you press enter in Sitecore RTE. It will generate <p> <br/> </p> tag. If you dont want it to generate paragraph text and you just want <br/> tags while pressing RTE. You can change below settings.



 <!--  HTML EDITOR LINE BREAK
            Specifies the tag that the HTML editor inserts on Enter. Values can be
            "br", "div" and "p".
      -->
      <setting name="HtmlEditor.LineBreak" value="br" />
   

Wednesday 8 June 2016

Sitecore - Use subdomains for multi tenant or multi sites



If you want to share domain/host name  across your tenant sites in Sitecore. You can achieve it using below site definitions

<site  name="CountryGerman" virtualFolder="/german" physicalFolder="/german"
             rootPath="/sitecore/content/SiteGerman" hostName="yourhostname" targetHostName="yourhostname"
            startItem="/home" database="web" domain="extranet" allowDebug="false" cacheHtml="true" htmlCacheSize="10MB"
            registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" filteredItemsCacheSize="2MB" language="en"
            enablePreview="true" enableWebEdit="true" enableDebugger="false" disableClientData="false" />            
 
<site  name="CountryIndia" virtualFolder="/india" physicalFolder="/india"
             rootPath="/sitecore/content/SiteIndia" hostName="yourhostname" targetHostName="yourhostname"
            startItem="/home" database="web" domain="extranet" allowDebug="false" cacheHtml="true" htmlCacheSize="10MB"
            registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" filteredItemsCacheSize="2MB" language="en"
            enablePreview="true" enableWebEdit="true" enableDebugger="false" disableClientData="false" />            

 
<site  name="main" virtualFolder="/" physicalFolder="/"
             rootPath="/sitecore/content/yoursite" hostName="yourhostname" targetHostName="yourhostname"
            startItem="/home" database="web" domain="extranet" allowDebug="false" cacheHtml="true" htmlCacheSize="10MB"
            registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" filteredItemsCacheSize="2MB" language="en"
            enablePreview="true" enableWebEdit="true" enableDebugger="false" disableClientData="false" />            



With above site definitions 

  • http://yourhostname will get resolved to "main" site. 
  • http://yourhostname/india will get resolved to "CountryIndia" site.
  • http://yourhostname/german will get resolved to "CountryGerman" site. 

Important - The order of site definitions are very important here. the default site which uses the default domain(not sub domain) should always come at last.  

This approach we can use even if we need a device specific or langauge specfic subdomain for the same site.

Sunday 5 June 2016

Enabling Developer Center in Sitecore 7.5 and above



Sitecore Developer Center is disabled in Sitecore 7.5 and above. It can be accessed via

http://hostname/sitecore/shell/default.aspx?xmlcontrol=IDE

but if you want to add it in Sitecore desktop mode under developer tools as in earlier version follow below steps.

1. Open Sitecore in Desktop mode.

2.  Change the database to Core either from changing the content db from bottom right or add a query string "?sc_content=core"





3. Right click on "/sitecore/content/Documents and settings/All users/Start menu/Right/Development Tools" item and add a Application shortcut with name Developer Center.


4. Put Application Link and Display Name field values as in below image.




5.  Go back to master db . You should be able to see Developer Center option under Developer Tools now.