Thursday, February 15, 2018

Getting SXA to work with Solr in Sitecore 9

When I started working with Sitecore 9 (initial release) and SXA 1.5.

I followed the instructions for installing Sitecore 9 and then Sitecore Powershell extension 4.7 and SXA 1.5.
I started exploring and everything seemed to work fine until I started working with page list and search components. These components need item query / search scope to be able to retrieve items based on certain query.
I was able to build the item query and go the results in the CM environment but when I publish the pages and load these pages, queries never returned anything.
Tried re-indexing, re-publishing but doesn't seemed to work.
Finally #Slack came to the rescue.

Here are couple of things that worked for me.
Fix 1
In Sitecore 9 initial release you need to enable one of the configuration file under Include\z.Foundation.Overrides depending on your search platform you are using. In my case it was Solr and hence I had to enable Sitecore.XA.Foundation.Search.Solr.config.
But enabling this caused my Solr master and web indexes failed to build and even the schema was not getting populated (Control Panel -> Populate Solr Schema).
Having no clue, someone in the slack #sxa channel mentioned that Sitecore 9 initial release have an issue in the above file. You need to remove the $id from the core and put the actual core name for your solr indexes. In my case it was xp1_master_index and xp1_web_index.
The changed configuration in Sitecore.XA.Foundation.Search.Solr.config is shown below with highlighted section

            Sitecore.XA.Foundation.Search.Providers.Solr.SolrSearchIndex, Sitecore.XA.Foundation.Search.Providers.Solr
                Sitecore.XA.Foundation.VersionSpecific.Search.ItemCrawler, Sitecore.XA.Foundation.VersionSpecific
            Sitecore.XA.Foundation.Search.Providers.Solr.SolrSearchIndex, Sitecore.XA.Foundation.Search.Providers.Solr
                Sitecore.XA.Foundation.VersionSpecific.Search.ItemCrawler, Sitecore.XA.Foundation.VersionSpecific

Fix 2
Una Vanhoeven also suggested to add couple of dynamic fields in Solr for master and web cores. Her blog explains it very well and hence not going to add same steps here.. Link to her blog

Once you are done with above two fixes, rebuild master index, re-publish and re-build web index. Now not only your master and web indexes will get built properly, your SXA components will also start working

Hope this helps

Friday, January 26, 2018

Error in Sitecore SXA theme selection


While working on SXA in Sitecore 9, I was facing an error in Sitecore experience editor where i was trying to select a theme. But it was throwing below error

Server Error in '/' Application.

End of string expected at position 51.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Sitecore.Data.Query.ParseException: End of string expected at position 51.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

[ParseException: End of string expected at position 51.]
   Sitecore.Data.Query.QueryParser.Raise(String error) +203
   Sitecore.Data.Query.QueryParser.DoParse(String query) +83
   Sitecore.Pipelines.GetLookupSourceItems.ProcessQuerySource.Process(GetLookupSourceItemsArgs args) +163
   (Object , Object[] ) +71
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +469
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +22
   Sitecore.Web.UI.HtmlControls.Data.LookupSources.GetItems(Item current, String source) +459

[LookupSourceException: Invalid lookup source "query:$compatibleThemes": End of string expected at position 51..]
   Sitecore.Web.UI.HtmlControls.Data.LookupSources.GetItems(Item current, String source) +623
   Sitecore.XA.Foundation.SitecoreExtensions.CustomFields.FieldTypes.LookupNameLookupValue.GetValueHtmlControl(String id, String value) +198
   Sitecore.XA.Foundation.SitecoreExtensions.CustomFields.FieldTypes.LookupNameLookupValue.BuildParameterKeyValue(String key, String value) +519
   Sitecore.XA.Foundation.SitecoreExtensions.CustomFields.FieldTypes.LookupNameLookupValue.BuildControl() +362
   System.Web.UI.Control.LoadRecursive() +68
   System.Web.UI.Control.LoadRecursive() +162
   System.Web.UI.Control.AddedControl(Control control, Int32 index) +11890468
   Sitecore.Web.UI.Sheer.ClientPage.AddControl(Control parent, Control control, String placeholder) +233
   Sitecore.Shell.Applications.ContentEditor.EditorFormatter.AddEditorControl(Control parent, Control editor, Field field, Boolean hasRibbon, Boolean readOnly, String value) +241
   Sitecore.Shell.Applications.ContentEditor.EditorFormatter.RenderField(Control parent, Field field, Item fieldType, Boolean readOnly, String value) +1490
   Sitecore.Shell.Applications.ContentEditor.EditorFormatter.RenderField(Control parent, Field field, Item fieldType, Boolean readOnly) +185
   Sitecore.Shell.Applications.ContentEditor.EditorFormatter.RenderField(Control parent, Field field, Boolean readOnly) +380
   Sitecore.Shell.Applications.ContentEditor.EditorFormatter.RenderSection(Section section, Control parent, Boolean readOnly) +252
   Sitecore.Shell.Applications.ContentEditor.EditorFormatter.RenderSections(Control parent, Sections sections, Boolean readOnly) +173
   (Object , Object[] ) +71
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +469
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +22
   Sitecore.Shell.Applications.ContentManager.Editor.Render(RenderContentEditorArgs args, Control parent) +558
   Sitecore.Shell.Applications.ContentManager.FieldEditorForm.RenderEditor(Border parent) +388
   Sitecore.Shell.Applications.ContentManager.FieldEditorForm.UpdateEditor() +187
   Sitecore.Shell.Applications.ContentManager.FieldEditorForm.OnPreRendered(EventArgs e) +37

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +210
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +146
   Sitecore.Reflection.ReflectionUtil.InvokeMethod(MethodInfo method, Object[] parameters, Object obj) +89
   Sitecore.Shell.Applications.ContentManager.FieldEditorPage.OnPreRender(EventArgs e) +164
   System.Web.UI.Control.PreRenderRecursiveInternal() +110
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3624


The issue was, I named my theme as "company-site". Please note "-" hyphen in between the name, which caused the fast query used to fetch theme names fail and was throwing above error. I renamed the them and it all started working