Posts

Unit Test for Sitecore Custom Personalization Rule

Image
I assume that in your career path you all become chance to hands on implementation for Sitecore Custom Personalization Rule. If you did not, then I have already described in detail about Custom Personalization Rule implementation in my one of previous blog. See the Blog Post: Custom Personalization Rules in Sitecore Today I am going to share with you about implementation of Unit Test for Custom Personalization Rule. Custom Personalization Rule business logic: protected override bool Execute(T ruleContext) { if (_pageContext != null && !string.IsNullOrWhiteSpace(_pageContext.baseketValue)) { var deliveryType = _basketDetailsService.GetBasket(_pageContext.basketValue).deliveryType; if (deliveryType != null && deliveryType== DeliveryType.CashOnDelivery) { return true; } } return false; } In above sample piece of code, I have created two Serv...

Sitecore Custom EXM Unsubscribe Page

Image
If you ever got a chance to implement the email campaign functionality using the default email template in EXM, then you may have observed that each email send to the users contains two links that are Unsubscribe and Unsubscribe from all from future emails campaigns. Requirement: When the user clicks on the Unsubscribe link in the email, instead of redirecting it to Unsubscribe.aspx page which is the default, the user should land on the custom page developed into the Sitecore. On the custom page, the user can choose the options from which list the user wants to unsubscribe. Solution: When the user clicks on the unsubscribe link, Sitecore default redirects to the RedirectUrlPage.aspx with decrypted query string parameter named ec_eq . The ec_eq query string parameter is the encrypted query string, and it is handled by the RedirectUrlPage.aspx process which handles the decryption of those parameters and returns Contact ID, Message-Id and others. On...

Sitecore Geolocation Service API

Image
 Sitecore provides location details of the user using Sitecore Geolocation API . It gives the detail of the Time zone, City, IP Address, region, Country, Post Code, Longitude and Latitude, etc. It is advantageous for marketers or developers in terms of visitor information, tracking, and personalization.  Using this information, you can apply the personalization rules for different geographical locations, tracking goals and page events. In this blog, I will let you know about How to enable the Sitecore Geolocation Service API and by using this API fetch the details of the user location using an IP Address. Enable Sitecore Geolocation Service API: First, you need to raise a request to Sitecore to activate the Sitecore IP Geolocation service. For the same, you can refer to Sitecore Documents. See the document: Set up Sitecore IP Geolocation Retrieve Geolocation Data: First, you need to make sure that XB and Analytics tracker is...

Execute PowerShell Script with Sitecore Scheduler

Image
If you have a requirement like execute PowerShell script in form of a scheduler then Sitecore Scheduler provides an option for the same. For Example, you want to delete some Sitecore Items after a specific date or remove the ideal user at some specific time. For that, you have written a PowerShell script instead of C# code and you want to schedule the PowerShell Script with a Scheduler. Then Sitecore Scheduler provides you a good option to execute PowerShell Script. If you want to know How to Install the PowerShell module with your Sitecore instance and the ideas about the PowerShell command and Scripts then, please refer series of blog posts written on: PowerShell with Sitecore . Here I am giving you an example to create a Sitecore Item using PowerShell Script and Schedule that Script by Sitecore Scheduler. You can update your PowerShell script as per your requirement. Step 1: Go to the PowerShell ISE, you can open it by Sitecore Launchpad or ...

Jobs in Sitecore

Image
Sitecore Jobs are used to calling the task or method which takes more time to execute. It allows us to start and execute the task in the background without affecting the other task and thread's executions. We can monitor the jobs via Admin section in {Sitecore- Instance}/sitecore/admin/jobs.aspx page . So, in one line you can say Sitecore Jobs are perfect options to run the long execution methods. Now the question is why Sitecore Job? Sitecore calls the <job> Pipeline to execute each job. Sitecore calls a separate thread for each job execution so that your code will be executed in the background without affecting any other method, thread block, etc. Sitecore also provided an admin section page to monitor the jobs. You can set the status and priority of the jobs. You can run multiple jobs at the same time without any interference. Sitecore Job provides job-related events like job:starting, job:started, job:ended , so tha...

Wildcard Item in Sitecore

Image
If the Sitecore item name is an asterisk (*) then the item is called a wildcard. So, Wild Card is a special page in our Sitecore content tree represented by the item name "*". Reason to create Wild Card Page: If we need to create large numbers of the content page using the same page template then we must apply the same rendering and presentation details on every content page. It’s very hectic for a content editor to create several pages and manages those pages into a content tree. To overcome this issue Wild Card Page is the best solution in which our all the data source we reside outside of the home node, somewhere in Global folder and we will have only a single wild card page which will serve all the data source pages. Let’s quick start, I have some products Under the Global/Product Folder , and I am creating a single Wild card page for all the products, that will display the information on the product: Create a Wild Card page i...

Sitecore Installation Error: Failed to Start Service 'Sitecore Marketing Automation Engine'

Image
 Error: [------- XConnectXP0_StartServices [2] : ManageService -----------------------] [XConnectXP0_StartServices [2]]:[Updating] sc903xconnect.dev.local-MarketingAutomationService Waiting for service 'Sitecore Marketing Automation Engine - sc903xconnect.dev.local-MarketingAutomationService (sc903xconnect.dev.local-MarketingAutomationService)' to start... Waiting for service 'Sitecore Marketing Automation Engine - sc903xconnect.dev.local-MarketingAutomationService (sc903xconnect.dev.local-MarketingAutomationService)' to start... Waiting for service 'Sitecore Marketing Automation Engine - sc903xconnect.dev.local-MarketingAutomationService (sc903xconnect.dev.local-MarketingAutomationService)' to start... Waiting for service 'Sitecore Marketing Automation Engine - sc903xconnect.dev.local-MarketingAutomationService (sc903xconnect.dev.local-MarketingAutomationService)' to start... Waiting for service 'Sitecore Marketing ...

Import CSV Data in Sitecore Using PowerShell: Part-3

Image
In my previous blog , we had discussed Sitecore PowerShell Command and Scripts. In this blog, I am discussing with you about How to Import CSV Data in Sitecore using PowerShell Scripts? To do the same you need to read the CSV file rows and create Sitecore Items into the Content Tree for each row then assign the column values of the row into the respective Item Field. There are two options: Write your own customized PowerShell Script and Import CSV Data. Use the inbuilt Data Importer tool that comes with Sitecore PowerShell Extension .  Option 1: Perform the Below steps to Import the CSV Data into Sitecore: First, you will need a CSV file. If you have Excel Sheet, then go to the File Menu and click on Save As option and change the format and save it into CSV format. Suppose you have a CSV file with the number of rows and each row has several columns with predefined values. Here I am taking the below CSV file for an...

PowerShell Commands and Scripts for Sitecore Item: Part-2

Image
In my previous blog , we had discussed Installation of the PSE module with Sitecore and Out of The Box Tools. In this blog, I am discussing with you some basic development of PowerShell Command and Scripts. Determine PowerShell version: Execute the below command will give you the all the details of installed PowerShell like Version, Edition, SPE module version, etc. In my case, I have installed SPE module 6.2.   $PSVersionTable Directory and Text file: Create a Directory into the system. Write text into the text file and save that text file in the system directory. Get Sitecore Item: You can get Sitecore Item by Path, ID, Sitecore Query. I am giving you an example with Path. In the above, I have set parameter value -ErrorAction SilentlyContinue which means the Get-Item command will execute without any error shown on the console in case it does not found any item on the path.   Now you ca...

PowerShell with Sitecore and Installation: Part-1

Image
PowerShell is a modern command-line shell, or we can say Scripting language framework.  It is a more influential tool compare to the command prompt. Sitecore PowerShell module increases your productivity, performance and saves your development time. It’s developed by Adam Najmanowicz and Michael West. It does not install OOTB therefore you need to install it manually. Using this module, you can perform serval operations on Sitecore Items like Add/Update/Delete, Get Child Items, Bulk Updates, Publish Items, Delete Items on specific conditions, etc. Install SPE Module: Go to the Sitecore Download website from here and select the Sitecore Version. Once you elect, it will redirect to the download section. Here I am selecting Sitecore Experience Accelerator 10.1.0, click on the link and it will redirect you to the  download section . Download the Sitecore PowerShell Extension for Sitecore. Install the Sitecore Po...

Make Sitecore Field Read-Only

Image
In this blog, I will discuss with you How to make Sitecore Item Field Read-Only. Scenarios: I have fetched the data from an external Database and create Sitecore items into the content tree and update the field values of items in the Sitecore content tree. There are Sitecore jobs that will run periodically and perform the above operations, but content editors can update those data and we can lose the actual values. Solution: As you are aware that access rights are applied on Sitecore Items so to resolve the above issue, I made the Sitecore item fields Read-only. Find below the steps to make the Sitecore Items field read-only: Go to the respective items template and find the field which you want to make read-only. Here I am doing with the Title field: In the Ribbon Bar menu click on the View button and make sure that both Standard fields and Raw values checkbox are checked: Go to the security section in the right panel and insert the below text into that security[shared] field and sav...

Pass Sitecore Items in .Net Class with Scheduler: Part-3

Image
In my previous blog , we had discussed Create and Configure Scheduler in Sitecore . At the end of this series of Sitecore Scheduler blogs, I will discuss with you about Pass Sitecore Items in the .NET class with Scheduler. Suppose in your .Net class your scheduler logic has some condition based on the Sitecore Items field values and to access those values you can opt for one of the below options: Get the Sitecore Item by its Item ID and write the logic of the get the respective field value by Item as below: var scItem = Sitecore.Context.Database.GetItem(new ID("{11111111-1111-1111-1111-111111111111}")); var fieldValue = scItem.Fields["Field Name"].Value; In the above approach, you have restricted the user for a constant ID and in the case of multiple items, your line of code will increase. Pass Sitecore Items into the Items field and get the values of those Sitecore Items fields by code. In this approach, you can pass multiple items and dynamically you can change...

Create and Configure Scheduler in Sitecore: Part-2

Image
In my previous blog , we had discussed Sitecore Scheduler . In this blog, I am going to discuss with you about How to create a scheduler in Sitecore and schedule it with the PowerShell interface. First, you need to write a class that will have the logic of functionality you want to execute.  namespace Helixbase.Foundation.Scheduler { public class DataImportScheduler { public void DataImport(Item[] items, Sitecore.Tasks.CommandItem command, Sitecore.Tasks.ScheduleItem schedule) { //Code here } } } The above piece of code will take three arguments: Array of Items Task command Item Task Schedule Item I will discuss with you more about the above three parameters in the next blog “Pass Sitecore Items”. Once you write your logic into .Net Class then you need to create Sitecore Command into Sitecore. Go to the path: “ /sitecore/system/Tasks/Commands ” and create a new command item. Right-click on the...

Sitecore Scheduler: Part-1

Image
In one of my projects, the client requirement was, to migrate data from an external Database to Sitecore Database and the import task should run automatically with a specific time interval on a scheduled day. In this blog I will discuss with you about Sitecore Scheduler in three sections: Sitecore Scheduler Create Scheduler in Sitecore Pass Sitecore items as a parameter in Scheduler As the name suggested, the scheduler is a task that gets executed with a defined interval in terms of the day, date, or can be a specific time in the day. There are three ways in Sitecore to schedule task in Sitecore CMS: Configure agent in web.config: It’s a very common and easy approach to create a scheduler in Sitecore. Using this approach, you have to restart the ASP.NET worker process as it requires changing into the web.config file. Create Window Task Scheduler or Window Service to call web service in Sitecore: In this approach, you can write a Window Service, or a Console application trigger it with...