Skip to content
January 13, 2021 / kiranpatils

PowerShell script to delete wrong Solr Config using Search Stax API

Challenge:

I’m a big fan of SearchStax as it removes all challenges to install, configure and manage Solr and let experts do experts job!

To set up Solr Collections: I always prefer to use Search Stax Plugin: https://github.com/searchstax/searchstax-sitecore-plugin

I made a mistake once where I had a typo in my config.yml and It uploaded config with the wrong name. (Garbage IN, Garbage OUT) Which I wanted to delete. But there was no way to do this via the plugin. So, I had to write a power shell using Search Stax API to do it and thought to share it with you!

Solution:

Disclaimer: I’m not yet proficient in Powershell. So, feel free to modify this script if you are Powershell NINJA!

You need to provide few values in the script and you should be good!

# "Please provide authentication information."
$uname = Read-Host Prompt 'Username – '
$password = Read-Host AsSecureString Prompt 'Password – '
$password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
Write-Host "Asking for an authorization token for $uname"
Write-Host
$body = @{
username=$uname
password=$password
}
Remove-Variable PASSWORD
$body = $body | ConvertTo-Json
try {
$token = Invoke-RestMethod uri "https://app.searchstax.com/api/rest/v2/obtain-auth-token/" Method Post Body $body ContentType 'application/json'
$token = $token.token
Remove-Variable body
Write-Host "Obtained token" $token
Write-Host
$searchstaxUrl = 'https://app.searchstax.com'
$ACCOUNT = 'TODO' # <- CHANGE YOUR VALUE HERE
$uid = 'TODO' # <- CHANGE YOUR VALUE HERE
$NAME = 'sitecore_sitecore' # <- CHANGE YOUR VALUE HERE
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Token $token")
#Delete Config
$RESULTS = Invoke-RestMethod Method Delete Headers $headers `
uri "https://app.searchstax.com/api/rest/v2/account/$ACCOUNT/deployment/$uid/zookeeper-config/$NAME/"
$RESULTS = $RESULTS | ConvertTo-Json
#return $token
} catch {
Write-Error Message "Unable to get Auth Token. Error was: $_" ErrorAction Stop
}

You can find API Documentation from here : https://www.searchstax.com/docs/staxapi2ZK/#zkdelete

January 13, 2021 / kiranpatils

SXA Lower case URL

Challenge:

As per SEO Best practice, We were trying to set all URLs to lower case for our SXA Solution.

Based on my NON-SXA Learning. I thought it will be changed in one place. But it had changed at one more place. Which I couldn’t locate easily from the documentation. So, thought to share with you to save your time!

Solution:

We made following change:

But that didn’t give us the desired results. A quick search helped us to find this post which outlines a few approaches: https://sitecore.stackexchange.com/questions/16504/sxa-search-results-render-link-url-lowercase (Thank you!)

We tried following config file and it worked!

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<linkManager>
<providers>
<add name="localizedProvider">
<patch:attribute name="lowercaseUrls">true</patch:attribute>
</add>
</providers>
</linkManager>
<links>
<urlBuilder>
<lowercaseUrls>true</lowercaseUrls>
</urlBuilder>
</links>
</sitecore>
</configuration>
view raw LowerCase.Config hosted with ❤ by GitHub
<rules>
<!– Take redirectType="Temporary" out of production if needed – Current live site has same configuration –>
<rule name="LowerCaseRule – not including querystring" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{PATH_INFO}" pattern=".*[A-Z]" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(sitecore)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(sitecore modules)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/-/" negate="true" />
<add input="{REQUEST_URI}" pattern=".*(-/media).*" negate="true" />
<add input="{REQUEST_URI}" pattern=".*(~/media).*" negate="true" />
<add input="{REQUEST_URI}" pattern=".*(~/icon).*" negate="true" />
<add input="{REQUEST_URI}" pattern="WebResource.axd" negate="true" />
<add input="{REQUEST_URI}" pattern="ScriptResource.axd" negate="true" />
<add input="{REQUEST_URI}" pattern="jsnlog.logger" negate="true" />
<add input="{REQUEST_URI}" pattern="Telerik.Web.UI.WebResource.axd" negate="true" />
<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(identity)" negate="true" />
</conditions>
<action type="Redirect" url="/{ToLower:{R:1}}" appendQueryString="true" redirectType="Temporary" />
</rule>
</rules>

One more thing — If you are also looking for a way to redirect any URL to lower case then this is a great post: https://blog.coates.dk/2018/01/15/lower-casing-rewrite-rules-breaks-the-sitecore-client/ – I had to modify it for Identity service – Added our version (Tested on Sitecore 9.3) in the gist above.

Happy SEO!

January 13, 2021 / kiranpatils

Workflow bundling bug

Challenge:

Since Sitecore 8.2 there is a hidden gem which allows you to do workflow bundling.

Workflow bundling means – When you move a page from one state to another using Experience editor only. All the associated component’s data sources on that page also move along with the page.

I’m surprised that this is not very well documented feature :

Following blog post has done good job outlining this (Thanks jammykam)

https://jammykam.wordpress.com/2016/09/05/sitecore-8-2-managing-datasource-components-and-workflow-from-the-experience-editor/ – Refer to “Workflow Bundling” section

If you don’t want to read the above post then for you – This flag controls workflow bundling behavior (Default value is true): “WebEdit.AffectWorkflowForDatasourceItem”

We have been happily using this functionality. But it stopped working and we couldn’t easily figure out when that happened as we were in between of new implementation.

If same is going on with you guys/girls as well. Then this post is for you!

Solution:

We started tracking all changes we made around this feature and we figured out that we had to disable comments as per our client’s request:

And that change was causing this behavior – Where, If we enable comment then it will work, and as soon as we disable comment it stopped working.

We raised the Sitecore support ticket and after some back and forth. Finally, Sitecore support was able to reproduce the issue and registered this as a bug (#452470). Unfortunately, there is no hotfix to fix this.

You must have to keep Workflow comments enabled (Which is as such a good practice) to use workflow bundling.

Hope this helps you figure out why your workflow bundling stopped working! 🙂

One more thing, There is also another bug with this feature where it doesn’t approve children items of a data source – https://trnktms.com/2018/03/20/webedit-affectworkflowfordatasourceitems-collect-datasource-children-items/ (“by default, this only collects the data source items and does not the children items of a data source. This is an issue when you have something like a list component which shows the children items”)

Happy Workflow bundling! 🙂

November 22, 2020 / kiranpatils

SXA Frontend (FED)-Backend (BED) Development Flow

I had a great time speaking at SUG Pune on SXA Frontend (FED)-Backend (BED) Development Flow

In case you missed to attend, You can go through following recording:

Key Slides:

Hope this helps you simplify your SXA FED-BED experience!

November 22, 2020 / kiranpatils

My Journey to become Sitecore MVP

I had great time speaking with Tamas Varga on my journey to become Sitecore MVP.

https://coresampler.fm/81

%d bloggers like this: