Thursday, August 15, 2019

Rich text Editors in sitecore


Most of the people know about this concept already,this is for people don't know about Rich text editor types in sitecore.

In sitecore there are 4 types of Rich text editors, please find below rich text editors and their screenshots. 4th and the 1st one doesn’t have the H1 options at all.

1)Rich Text Default:
Template field to update: /sitecore/system/Settings/Html Editor Profiles/Rich Text Default




2)Rich Text Full
    
Template field to update:   /sitecore/system/Settings/Html Editor Profiles/Rich Text Full



    3) Rich Text IDE

    Template field to update:  /sitecore/system/Settings/Html Editor Profiles/Rich Text IDE




    4) Rich Text Medium

    Template field to update: /sitecore/system/Settings/Html Editor Profiles/Rich Text Medium



    you can configure the rich text editor on your template field like below


    Wednesday, August 14, 2019

    Writing a power shell script update the Url's the environment you are on

    Scenario:
    whenever you will get the latest content from Prod to QA.you will see some Url's still pointing to Prod.
    below powershell script will find the particular Url and replace the Url of your current environment
    it will traverse through all child items and replace the text wherever it is.it's time consuming if you have a big site.running the script by folder by folder,will be faster.

    Using the bulk update below is the final script
    $path="/sitecore/content/SomeSite/Home";
    $findField="*http://www.Illinoiindinas.com*";
    $originalText="http://www.Illinoiindinas.com";
    $replaceWith="http://SitecoreQa.illinoindians.com";
    $count=0;
    $items=Get-ChildItem -Path $path -Recurse
    New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
    foreach($item in $items){
        foreach($field in $item.Fields){
        if($field -like $findField)
        {
            $newValue= $field -Replace($originalText,$replaceWith)
            $item.Editing.BeginEdit()
            $field.Value=$newValue;
            $item.Editing.EndEdit() > $null
            $count=$count+1
            $StringToDisplay=[string]::format("Items updated {0} with fields {1}",$item.ID,$field.Name)
            Write-Host $StringToDisplay
        }
    }
    }
     Write-Host "Number Of Fields Updated:" $count
    }


    the above script is using the BulkUpdateContext,it will useful whenever you want to update the bulk content.and also you can add the security disabler. Sitecore.SecurityModel.SecurityDisabler

    Point to Note:
            It's not always most efficient to operate on items by traversing the tree using Get-ChildItem
    you can use the Sitecore QUery and Fast query as well,whenever working with the bulk items

    Based on

    Running a Powershell Script by scheduled Task

    Sitecore version:8.2.

    You can find lot of articles online,for my reference posting this article.
    Running powershell script for scheduled task is not that complex,you can create a powershell script and run schedule basis.the below script is for clearing the cache on a schedule basis, best practice is not to clear the cache often,it will effect to your site performance.

    Basic script:
    ForEach($site in [Sitecore.Configuration.Factory]::GetSiteNames()) {
        $siteInfo = [Sitecore.Configuration.Factory]::GetSiteInfo($site)
        if($siteInfo -ne $null) {
             $siteInfo.HtmlCache.Clear()  
             $logEntry = [string]::Format("mahe through Scheduled Task your HtmlCache.Clear() invoked for {0}", $siteInfo.Name)
             Write-Log $logEntry
             Write-Host $logEntry
        }
    }
    1)      Write above script in your powershell ISE and excute if it’s working fine save as [some name] PowerShellHtmlCacheClearTask
    2)      /sitecore/system/Modules/PowerShell/Script Library/Task Management/Content Editor/Insert Item/PowerShellHtmlCacheClearTask








     Creating the Scheduled Task
    1.  Goto /sitecore/system/Tasks/Schedules
    2.  Click on the Schedules and insert PowerShell Scripted Task Schedule




    1     Give the name SchedulePowerShellScript
    2     Select the Powershell task you created in 1st step
           Click on the create



    Select the timings when you want to run and how often it should run



    You will see on the SPElogs your task running