Sitecore Scheduled Publishing not working after installing Initialize Speed Booster Package

After installing the Initialize Speed Booster Package you might face an issue when scheduling a task, in order to make the scheduled task working comment the below code from the App_Config/include/zzz/InitializeSpeedBooster.config

<processor type="Sitecore.Pipelines.Loader.InitializeScheduler, Sitecore.Kernel">
  <patch:delete />
</processor>
Advertisements

Segment Records Reduce Functionality

Sitecore Sharing

If you compare between Sitecore with Google analytics, you will see there are differences between collected data, this is expected as they use two different ways of gathering information:

  • Google Analytics is a JavaScript-based client-side technology, while Sitecore Analytics is a .NET-based server side one, which typically means more accurate data.
  • Sitecore does not count all the incoming requests, It uses ASP.NET sessions and browser cookies to distinguish unique users.

But, there is important thing,  you have to be aware of, it’s Sitecore Reduce functionality.

What is Reduce functionality ?

In Sitecore, the aggregation subsystem will collect facts (visits and value number per day) about every group of every dimension e.g. for country,city,region dimension you have all the countries and cities etc. Also Dimension key can stores unique statistic information about triggered goals, Country value etc.

The reducer will roll-up the least important groups(let say countries) per day into a single…

View original post 297 more words

Saving and Auto Refreshing Sitecore Experience Editor Page after the update using Edit Frames or Buttons

EditFrames in the Experience Editor is a feature that you can use to give users front-end access to fields that are not directly accessible, either because they are not visible or they are of a type that is not directly front-end editable.

When editing a component using EditFrame or the Editor Button the component datasource does not refresh. To do this, you have to save the page first and then it reloads the page with the latest change this is too annoying for the content editors.

We can achieve this by overriding the Sitecore Pipelines

  • Sitecore.Shell.Applications.ContentManager.ReturnFieldEditorValues.SetValues
public void Process(ReturnFieldEditorValuesArgs args)
{
    Assert.ArgumentNotNull(args, nameof(args));

    args.Options.SaveItem = true;
    foreach (FieldInfo fieldInfo in args.FieldInfo.Values)
    {
        Control subControl = Context.ClientPage.FindSubControl(fieldInfo.ID);
        if (subControl == null) continue;

        var value = subControl is IContentField
            ? StringUtil.GetString((subControl as IContentField).GetValue())
            : StringUtil.GetString(ReflectionUtil.GetProperty(subControl, "Value"));

        if (value == "__#!$No value$!#__") continue;

        string type = fieldInfo.Type.ToLowerInvariant();
        if (type == "rich text" && type == "html") continue;

        value = value.TrimEnd(' ');

        foreach (FieldDescriptor fieldDescriptor in args.Options.Fields)
        {
            if (fieldDescriptor.FieldID != fieldInfo.FieldID) continue;

            ItemUri itemUri = new ItemUri(fieldInfo.ItemID, fieldInfo.Language, fieldInfo.Version,
                Factory.GetDatabase(fieldDescriptor.ItemUri.DatabaseName));
            if (fieldDescriptor.ItemUri == itemUri)
                fieldDescriptor.Value = value;
            Item item = Factory.GetDatabase(fieldDescriptor.ItemUri.DatabaseName)
                .GetItem(itemUri.ItemID);

            if (item == null) continue;

            item.Editing.BeginEdit();
            item.Fields[fieldInfo.FieldID.ToString()].Value = value;
            item.Editing.EndEdit();
        }
    }
}

  • Sitecore.Shell.Applications.ContentManager.ReturnFieldEditorValues.ReturnAndClose
public void Process(ReturnFieldEditorValuesArgs args)
{
    Assert.ArgumentNotNull(args, nameof(args));

    SheerResponse.SetDialogValue(args.Options.ToUrlHandle().ToHandleString());
    SheerResponse.SetModified(true);
    SheerResponse.CloseWindow();

    SheerResponse.Eval("window.top.location.reload();");
}

Create a Sitecore Patch file

Create a new Patch file inside the /App_Config/Include folder. The following is the Sitecore patch file with an example of how the custom pipelines is added.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"><sitecore>
    <processors>
        <uiReturnFieldEditorValues>
            <processor type="YourNameSpace.SetValues, YourAssembly"
            patch:instead="processor[@type='Sitecore.Shell.Applications.ContentManager.ReturnFieldEditorValues.SetValues']" />
            <processor type="YourNameSpace.ReturnAndClose, YourAssembly"
            patch:instead="processor[@type='Sitecore.Shell.Applications.ContentManager.ReturnFieldEditorValues.ReturnAndClose']" />
        </uiReturnFieldEditorValues>
    </processors></sitecore>
</configuration>

Prevent Duplicate Items in Sitecore

During one of the Sitecore integrations, our customer faced the issue by creating duplicate items. This makes us create a new Event in Sitecore.

What is an Event?

Events in Sitecore are similar to the events in other systems, something triggers an event and there are handlers that are configured to handle the event.

Create an Event Handler

While there is neither a class to extend nor an interface to implement, a convention must be followed in order for Sitecore to be in order for a class to be used as an event handler.

The class must have OnItemCreating method that accepts object and EventArgs

public void OnItemCreating(object sender, EventArgs args)
{
        
   Assert.ArgumentNotNull(sender, "sender");
   Assert.ArgumentNotNull(args, "args");

   using (new SecurityDisabler())
   {
       ItemCreatingEventArgs arg = Event.ExtractParameter(args, 0) as ItemCreatingEventArgs;

       if (Sitecore.Context.Site.Name == "shell")
       {
            var firstOrDefault = arg.Parent.GetChildren()
                                            .FirstOrDefault(x => (arg.ItemName.Equals(x.Name, StringComparison.OrdinalIgnoreCase)) && (arg.ItemId != x.ID));
            
            if (firstOrDefault != null && firstOrDefault.Fields[FieldIDs.LayoutField] != null && !string.IsNullOrEmpty(firstOrDefault.Fields[FieldIDs.LayoutField].Value))
            {
                ((SitecoreEventArgs)args).Result.Cancel = true;
                Sitecore.Context.ClientPage.ClientResponse.Alert($"Item '{firstOrDefault.Name}' already exists!");
                return;
            }
        }
   }
}

After the event handler is written, it must be added to the event definition.

Create a Sitecore Patch file

Create a new Patch file inside the /App_Config/Include folder. The following is the Sitecore patch file with an example of how the custom event handler is added.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore><events><event name="item:creating"><handler type="YourNameSpace.PreventDuplicateItem, YourAssembly" method="OnItemCreating"/></event></events></sitecore>
</configuration>

Steps to Install Sitecore 9 using SIF Less

Using SIF Less tool, it was pretty easy to install Sitecore 9, Following steps helps to Install Sitecore 9 smoothly.

STEP 1: Open command prompt with Administrator Rights

STEP 2: Download/Install Chocolatey from https://chocolatey.org/install

Install with Command line

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Install with Powershell

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

STEP 3: Install Microsoft Web Platform from https://www.microsoft.com/web/downloads/platform.aspx

STEP 4: Make sure that you have installed/install the Following Modules using Microsoft Web Platform Installer

  • URL Rewrite
  • Web Deploy 3.6 for Hosting Services
  • DACFx – Microsoft SQL Server Data-Tier Application Framework
  • ScriptDom – Microsoft SQL Server 2012 SP1 Transact-SQL ScriptDom (Latest)

STEP 5: Download & Install SQL Server Data Tools (SSDT) from Microsoft or using Chocolatey

choco install ssdt15

FYI: you need download/install the version based on your SQL server. For SQL 2017 it should be ssdt17

STEP 6: Download & Install Java Runtime using Chocolatey

choco install javaruntime

STEP 7: Download Solr 6.6.2 from http://archive.apache.org/dist/lucene/solr/

STEP 8: Extract the Zip file downloaded and to Copy to C drive (eg: c:\solr-6.6.2)

STEP 9: Download & Install NSSM – the Non-Sucking Service Manager

choco install nssm

STEP 10: Register Solr Service using NSSM

nssm install solr

It will show the NSSM Installer, there you need to provide the Path to the Solr and also pass the arguments along with the port 8983 or as you wish.

 

nssm

STEP 11: Start Solr

nssm start solr

To test the solr you can browse http://localhost:8983/solr

STEP 12: Open Powershell using Administrator mode.

STEP 13: Now we need to enable the SSL for Solr, to do go-to https://kamsar.net/index.php/2017/10/Quickly-add-SSL-to-Solr/ and you can find the Powershell script and follow the steps mentioned in the article.

  1. Open the solrssl.ps1 script in notepad or any editor
  2. Provide the path for keytool.exe on line 37 (eg. C:\Program Files\Java\jre1.8.0_181\bin\keytool.exe)
  3. Save the File
  4. Open the Windows Powershell in Administrator mode.
  5. Navigate to the folder where the solrssl.ps1 saved.
  6. Run the script
    .\solrssl.ps1 -KeystoreFile C:\solr-6.6.2\server\etc\solr-ssl.keystore.jks

STEP 14: Now open the Solr folder in the filesystem (eg: C:\solr-6.6.2\bin) and find solr.in.cmd and edit this file using notepad and uncomment the below lines

REM Uncomment to set SSL-related system properties
REM Be sure to update the paths to the correct keystore for your environment
set SOLR_SSL_KEY_STORE=etc/solr-ssl.keystore.jks
set SOLR_SSL_KEY_STORE_PASSWORD=secret
set SOLR_SSL_KEY_STORE_TYPE=JKS
set SOLR_SSL_TRUST_STORE=etc/solr-ssl.keystore.jks
set SOLR_SSL_TRUST_STORE_PASSWORD=secret
set SOLR_SSL_TRUST_STORE_TYPE=JKS
set SOLR_SSL_NEED_CLIENT_AUTH=false
set SOLR_SSL_WANT_CLIENT_AUTH=false

STEP 15: Restart Solr

nssm restart solr

now you can open the Solr using https://localhost:8983/solr

STEP 16: Register the Powershell NuGet Repository and Install the modules, you can find more information from https://doc.sitecore.net/sitecore_experience_platform/developing/developing_with_sitecore/sitecore_powershell_public_nuget_feed_faq

STEP 17: Create a Folder in C drive or any other drive of your choice and name it “Sitecore”

STEP 18: Create a folder inside and name it as “Configuration”

STEP 19: Go-to Sitecore Downloads https://dev.sitecore.net/

STEP 20: Go-to options for On-Premises deployment, and download Packages for XP Single

STEP 21: Extract the files in the folder you’ve created in Step 17.

STEP 22: Now you extract the Zip file starts with XP0 Configuration* to the Configuration folder created in STEP 18.

STEP 23: Download the SIF Less Tool from https://bitbucket.org/RAhnemann/sif-less/downloads/SIFLess.zip

Find more information from http://www.rockpapersitecore.com/2017/10/introducing-sif-less-for-easy-sitecore-9-installation/

Generate the Powershell Script using SIF Less and you can find the generated file inside the same folder where you run the SIF Less tool.

STEP 23: Now Run the Install Script from the SIF Less tool. It will take some time to install the Sitecore 9 and you can start using it.

STEP 24: Congratulations! your Sitecore 9 setup is done.

Hope this article helps,

Link to an Item in Sitecore Content Editor from Custom Sitecore Application

Sitecore is flexible to allow customizations, and also to include in Sitecore Application itself. In some cases, we need to link to an item inside the content editor. Below extension method will help to convert to Content Editor Url.

Here I’m sending id and fo parameter with the Sitecore Item ID as value, along with the language of the target Item.

public static string ContentEditorUrl(this ID id, string language)
{
	return $"/sitecore/shell/Applications/Content Editor.aspx?id={id.ToString()}&la={language}&fo={id.ToString()}";
}

public static string ContentEditorUrl(this ID id)
{
	return ContentEditorUrl(id, "en");
}

Sitecore Missing Language Version Warnings

Display warning icon, if there is any language version is missing on a Multi-lingual Sitecore Website. This can help to create missing language versions in Sitecore. It saves a lot of time for content editors to go and find where the language version is missing and which language is missing.

Watch the below video how the language warning helps an editor to identify which language is missing.

You can download the source code from my GitHub page.

Following Steps needs to be done, after you create the Missing Languages Gutter Renderer

  1. Go-to Sitecore and Switch to Core Database
  2. Then Goto > Sitecore > Content > Applications > Content Editors > Gutters
  3. Create a new Gutter Item
gutter

Once you finished the above, you can switch to the master database.

To Enable the Gutter:

Right-click in the gutter to enable your Language Warnings, and then you can see your language missing icon wherever an item doesn’t have the versions.