Hishaamhttps://hishaamn.wordpress.com
My Sitecore Journey
Tue, 23 Oct 2018 06:56:06 +0000 en
hourly
1 http://wordpress.com/https://s0.wp.com/i/buttonw-com.pngHishaamhttps://hishaamn.wordpress.com
Sitecore – Source Query with respect to languagehttps://hishaamn.wordpress.com/2018/10/22/sitecore-source-query-with-respect-to-language/
https://hishaamn.wordpress.com/2018/10/22/sitecore-source-query-with-respect-to-language/#respondMon, 22 Oct 2018 15:12:00 +0000http://hishaamn.wordpress.com/?p=3793When creating templates in Sitecore, you can allows to target specific items to be selected by content authors. In order to achieve this, Sitecore Datasource are used. Most of the time, datasources are mainly use with a Multi-List field, DropList field, DropLink field. The list goes on and on. The datasource also allows to have a query which you can easily setup. However, out of the box Sitecore, you cannot have a query which allows you to filter the list of items based on the language.

Let say you have a container which holds several items and are shared across different sites. Now, you have a Multi-List field whereby a content author should select from. The tricky part here is that, for example, if the content author is updating a content for the en-US site, the Multi-List field should show only items from the main container which has at least 1 version in en-US.

In today’s article, I will explain how to achieve the above. OOTB Sitecore, this is not possible using Sitecore queries because Sitecore does not take into account which language has been selected when updating an item.

Get Lookup Source Item

You can use the Lookup Source Item pipeline (<getLookupSourceItems>). This particular pipeline is responsible to execute the Sitecore query you’ve filled in the Datasource Field. Moreover, you can implement your business logic to retrieve items.

Implementation

You will need to implement a method which has GetLookupSourceItemsArgs as parameter. The args paramter has a property named Item which contain the selected item in the current selected version.

Configuration File

Once you implemented the code, you need to add it to the getLookupSourceItems pipeline. Below is an example of the patch.

Testing

Based on the above code, I tested it by creating a container item named Items holding 3 items

Item with English version only

Item with French version only

Item with both English and French version

English Version Selected

French Version Selected

Upon selection of a language version, the items from the Multi-List Field changes the list of items.

]]>https://hishaamn.wordpress.com/2018/10/22/sitecore-source-query-with-respect-to-language/feed/0Resource Center Headernhishaam12[PART I] Sitecore Rule Engine – Introductionhttps://hishaamn.wordpress.com/2018/09/05/part-i-sitecore-rule-engine-introduction/
https://hishaamn.wordpress.com/2018/09/05/part-i-sitecore-rule-engine-introduction/#respondWed, 05 Sep 2018 19:43:48 +0000http://hishaamn.wordpress.com/?p=3783Sitecore Rule Engine is powerful as it allows you to decouple business logics from the code. This post is one of the list of articles that I will be writing up about the Rule Engine. Based on different projects I have been working, questions from SSE or Sitecore Slack Channel, I will try to go a bit more in depth and talking about the Rule Engine.

So, in today’s post, I will mainly focus on the Six Ws:

What is the Rule Engine.

What can you do with it.

Why should you use it.

How do you use it.

There are lots of information about the Sitecore Rule Engine already available on the net and I will list down some of them at the end.

What is the Rule Engine?

The rule engine evaluates a set of rules that the user has configured and trigger the respective actions. First, let’s break this down.

A rule consist of one or more conditions and/or actions. Basically, a user will configure the rule on the Rule Set Editor by adding conditions and actions. Below is a screenshot of the Rule Set Editor.

The user will just need to click on the desire conditions or actions and those will get displayed in the Edit Rule Section. Note that there is already a list of predefined base conditions and actions in Sitecore. Modules like WFFM when installed also comes with a list of conditions and actions that you can easily use with any code change.

Moreover, the dialog of the Rule Set Editor may vary. For example, when adding personalization on a component in the Experience Editor, you will see only the conditions column.

What can you do with it?

In this section, I will provide some examples where Sitecore Rules can be used. Rules can be triggered on both Back Office (CMS) and Front Office (Live Site).

– Lookup Source Location

You can implement different conditions and actions and have them executed in the Content Editor. Lookup Source Location is one example whereby when a user selects an item in the content tree, the rules are triggered, evaluates the conditions and return the proper source of a Sitecore field. With this, you can reduce development time as you can configure different rules and have them executed based on your requirements.

Example: You have 2 different sites and both of them have a MultiList Field. The source of the field should be dynamic. So, if I am on Site A, the multilist should show items under the Site node A and if I am on Site B, the source should point to the items under Site node B.

– Sitecore Agents

The rules can be used to capture part of the business logic when performing a Sitecore Tasks/Agents. By this, I mean, you can configure how your agent behaves.

Example: You need to implement an agent whose task is to change ordering of items in the Content Tree. The other requirement here is that the ordering type is different based on specific templates. So, instead of implementing different agents, you can still has 1 agent coupled with the rules. I know you can have the parameters set into configurations files but if you need to change the parameters often, then you will require to deploy those changes causing app pool restart and so on.

– Personalization

Most Sitecore projects where rule engine has been used are mainly for personalization. You can configure different rules on components and based on the actions, the contents being rendered by that component will differ based on user interactions.

Example: You have a site which displays contents about sports. You want users who are sprinters to see Banner A, swimmers to see Banner B and footballer to see Banner C. Personalization rules allows you achieve the above requirement and if I am not mistaken, it is an OOTB feature in Sitecore.

Why should you use it?

Sitecore rules is very useful and powerful. It allows you to minimize development time. Instead of hard coding or storing values in configuration files, you can easily store them as parameters in the conditions or actions. Furthermore, you can implement the rules in simple english/french/german/spainish… sentences, which means in terms of readability, it is a lot much easier to understand the business logic.

My personal opinion why I would use the Rule Engine is because of personalization. Nowadays, every person wants to get relevant contents. And from the OOTB Sitecore rules, you can achieve this.

How do you use it?

From the Rule Editor, you are presented with a list of conditions and actions. When you select a condition or action, it will populate the below space with the rule. From there, you can configure the different values that you need based on your requirement.

In the experience editor, the Rule Editor differs. Below is a screenshot showing how the Rule Editor is displayed.

Predefined Rules

You may have complex rules and instead of configuring those rules on each component, you can define the rules in the Predefined Rules. It is available at the path /sitecore/system/Marketing Control Panel/Personalization/Predefined Rules and you can create different Conditional Rendering Rules.

]]>https://hishaamn.wordpress.com/2018/09/05/part-i-sitecore-rule-engine-introduction/feed/0Resource Center Headernhishaamrule set editorCapture.PNGCaptureSitecore – Reading Solr Cores Dynamicallyhttps://hishaamn.wordpress.com/2018/08/29/sitecore-reading-solr-cores-dynamically/
https://hishaamn.wordpress.com/2018/08/29/sitecore-reading-solr-cores-dynamically/#respondWed, 29 Aug 2018 08:12:43 +0000http://hishaamn.wordpress.com/?p=3780In Sitecore, you have 4 main types of search you can performed. Those are

Sitecore Fast Query

Sitecore Query

Sitecore Search Index

In today’s post, I will be concentrating on the Sitecore Search Index. Using indexes increase the performance of an application.

Querying the Solr cores is very simple and there are different ways to do so. Normally, when querying the Solr cores, we inherit the SearchItemResult to a custom class and define some property decorated with IndexField attribute. But with this approach, I cannot query the cores dynamically by passing the field name as parameter.

So, how to query the cores dynamically?

In Solr, you will see that field names have a suffix like _s, _d and so on. If you are going to pass the field name, for example, title, it will not work. The reason is because, solr will try to perform a match of the field name with the one from the core. Solr will expect to have the field name as title_s.

In order to achieve it, you can use the below code.

From the above code, by using the method GetIndexFieldName(), it will provide the field name from the core.

Another solution is to add the field name in the section “<fieldNames hint=”raw:AddFieldByFieldName”>” in the Default Index Configuration file. You just need to add the field name as shown below

]]>https://hishaamn.wordpress.com/2018/08/29/sitecore-reading-solr-cores-dynamically/feed/0sitecore-solr-1nhishaamSitecore – Add, Update and Reset Profile keys Programmaticallyhttps://hishaamn.wordpress.com/2018/08/01/sitecore-add-update-and-reset-profile-keys-programmatically/
https://hishaamn.wordpress.com/2018/08/01/sitecore-add-update-and-reset-profile-keys-programmatically/#respondWed, 01 Aug 2018 14:17:18 +0000http://hishaamn.wordpress.com/?p=3776I had a site whereby there were around 2400 editorial contents. Out of those 2400 contents, only 1000 contents had a proper tagging and proper values for the profile keys. In order to update all those profile keys, I had to write a code to update those content.

First, I read the values from a CSV file and pass the values as parameters in my method. The method implementation is describe below. I have 4 profile keys that I had to update for a Profile Card.

Now, there were some cases whereby I had to reset the Profile card that has been tagged on the contents. The below method is very similar to the one above but the main change is at line 45.

In brief, it will loop through the xml document and only add profiles that does not match my profile card name.

This is the class for the Profile Key

]]>https://hishaamn.wordpress.com/2018/08/01/sitecore-add-update-and-reset-profile-keys-programmatically/feed/0Sitecore Analytics vs Google AnalyticsnhishaamSitecore Powershell Extract Profile Cardshttps://hishaamn.wordpress.com/2018/07/11/sitecore-powershell-extract-profile-cards/
https://hishaamn.wordpress.com/2018/07/11/sitecore-powershell-extract-profile-cards/#respondWed, 11 Jul 2018 11:59:29 +0000http://hishaamn.wordpress.com/?p=3774Recently, I had a request from the client to provide him with the list of profile cards that were used to tag contents. Again Sitecore Powershell is here to rescue. I sat and it took me around 15 minutes to write up and test the script. In this small article, I will share the script I have written and also, how you can customize it for your own requirement.

Below is the script I have written

The script is configurable by changing the path and the language.

And here is the function ​CleanQueryPath implementation.

]]>https://hishaamn.wordpress.com/2018/07/11/sitecore-powershell-extract-profile-cards/feed/0externalcontentpostfeaturedimagenhishaamSitecore Powershell Dynamic UIhttps://hishaamn.wordpress.com/2018/06/30/sitecore-powershell-dynamic-ui/
https://hishaamn.wordpress.com/2018/06/30/sitecore-powershell-dynamic-ui/#respondSat, 30 Jun 2018 10:09:26 +0000http://hishaamn.wordpress.com/?p=3770Sitecore powershell has changed my day to day work. Changing datasource, extracting data or creates items in Sitecore using SPE can be performed in seconds by just writing up the scripts and run it. I had a requirement whereby I need to dynamically show the user a UI which is rendered dynamically based on his input.

Scenario

We need to create multiple categories along with its sub categories for a site. Since the number of categories and sub categories differs for each site, we cannot hard code the text fields. It should be generated dynamically.

Implementation

First thing is to show the user an input box where he can enter the number of categories. Here is the snippet of the script

And here is how the window looks like

Upon clicking on the Proceed button, we need to capture the input value and creates another UI for the user to be able to add the name of the categories.

From the above screenshot, the user has input 3 in the number of categories (first screenshot) and since the user wants to create 3 categories, the next window dynamically shows 3 text boxes to the user. If 4 was input, it would be 4 text boxes.

The real magic occurs when calling the Invoke-Expression. This will convert the string pattern to an expression that the -Parameters can understand.

Below is the full SPE script for the above scenario

]]>https://hishaamn.wordpress.com/2018/06/30/sitecore-powershell-dynamic-ui/feed/0externalcontentpostfeaturedimagenhishaamcategoriesdynamic.PNGSitecore – Add my stuff to Analytics Indexhttps://hishaamn.wordpress.com/2018/06/06/sitecore-add-my-stuff-to-analytics-index/
https://hishaamn.wordpress.com/2018/06/06/sitecore-add-my-stuff-to-analytics-index/#respondTue, 05 Jun 2018 20:58:04 +0000http://hishaamn.wordpress.com/?p=3761I have been writing articles about how to aggregate data from MongoDB to Sitecore SQL Reporting database. But it new occurred to me that I can also have some of my data to be added to the Sitecore Analytics Index. For this article today, I will be explaining on how you can add custom data to the Sitecore Analytics Index. I’ll take the following scenario.

You want to add the assets that have been downloaded by a user. So, when the user downloads, for example, on a PDF file, you want to have a report at the end of the month to show which users have downloaded the file.

Previously, I would have implemented a custom aggregator which will flush the data to a custom table in the Sitecore SQL Reporting Database and then by using either Sitecore APIs or Entity Framework, I would have query the database to pull out the result. This is one solution. Second solution is to add those to the Analytics Index which makes more sense for me because I will need only 3 fields, which are the contact id, the date and the file which has been downloaded.

How to add to Sitecore Analytics Index?

Theory first! This is very well explained by our friend Adam Conn. Sitecore aggregators are not use only to aggregate data from MongoDB to the SQL Reporting Database. It is also used to update the Sitecore Analytics Index. Once the session of the user expires, you have an entry in the Sitecore Tracking Collection in MongoDB. This entry identifies the interaction that represents the session activity.

Here is a diagram which explains how the aggregators push the data to the Analytics Index.

Sitecore makes use of Crawlers. Each crawler that indexes the analytics database inherits from the ObserverCrawler<T> type. The generics type identifies the kind of IIndexable object the crawler handles. For example, one of the crawler handles visit objects and another crawler handles contact objects.

When the crawler is initialized it registers itself as an observer for the generics type. So the contact object crawler registers itself as an observer for ContactIndexable objects. Being an observer means the crawler is notified when it needs to take action. Not only is the crawler notified, but the notification process also passes data (an IIndexable object) to the crawler. The crawler, then, uses this data to update the analytics index.

The Code

Crawler

Let us first implements the crawler. The below snippet shows that the crawler AnalyticsDownloadCrawler inherits the class AnalyticsObserverCrawler of type DownloadEventIndexable

The download event indexable implementation is as follows. As you can see below, in order to load the fields, we need to trigger a custom pipeline. That pipeline will allow us to load and add custom fields into the index.

Let’s implement the class which will hold the arguments.

Once you have the argument setup, you need to implement the pipeline which will run the method to add the fields.

This is the processor which will add the data to the index fields. If you want to change or add new fields, this is where it should be done.

As you can see from the above code, I have added a custom field with the name contact.download. This will get push to the index at the end of the process. Moreover, the class inherits another one. This is required for it to be able to resolve the processor at runtime. The code snippet is provided below.

As mention above, you will require an aggregator which will convert the data from mongoDB to IIndexable and then pass it to the interaction pipeline.

Once the code implementation has been done, you need to patch those 2 config files

Sitecore.ContentSearch.Lucene.Index.Analytics.config

Sitecore.ContentSearch.Analytics.config

Sitecore.ContentSearch.Lucene.Index.Analytics.config

Sitecore.ContentSearch.Analytics.config

Below is a screenshot of the values in the sitecore analytics index

Here is the list of dlls I have referenced in my solution

Sitecore.Analytics.dll

Sitecore.Analytics.Aggregation.dll

Sitecore.Analytics.Model.dll

Sitecore.kernel.dll

Sitecore.Abstractions.dll

]]>https://hishaamn.wordpress.com/2018/06/06/sitecore-add-my-stuff-to-analytics-index/feed/0CapturenhishaambAjgR.pngSitecore Click-stream Analyticshttps://hishaamn.wordpress.com/2018/05/17/sitecore-click-stream-analytics/
https://hishaamn.wordpress.com/2018/05/17/sitecore-click-stream-analytics/#respondThu, 17 May 2018 17:18:17 +0000http://hishaamn.wordpress.com/?p=3753Personalized contents are everywhere now. In order to drive more sales or show the best contents to users, marketers define strategies on to allow users to be exposed to contents or offers which are meant for them. I had a requirement where I had to track the user content flow on one of our sites.

The requirement was very simple; When a user arrives on the site, we need to track every click and view he/she performs on the site along with goals. To be able to achieve this, I have use the Sitecore Page Events. In this article, I will be explaining how you can achieve the click-stream.

Summary

Create a category for the content click event in Sitecore.

Add a checkbox whether a content should have its click event tracked.

Implementation of a method to register the Page Event in MongoDB.

Implementation of an aggregation processor to take data from MongoDB to SQL Reporting Database.

The first thing is to create a Sitecore checkbox field type on the template called Track Performance. The functionality of this field is whether you want to track the click on this content. For example, you may want to track content A but not a static page such as about us page.

Create a Page Event Category under the path /sitecore/system/Settings/Analytics/Page Events. Example, you can named it Content Events Click. You need to implement a handler for the item:saved so that if the Track Performance is checked, then the handler will need to create an item at the path /sitecore/system/Settings/Analytics/Page Events/Content Events Click. Below is the code snippet of the ItemSavedEventHanlder.

When items are saved, it will create a Page Event item. Please see below screenshot.

Now, when user navigates on the site and performs clicks, you need to perform a call to a method which will register the click event into MongoDB. The code snippet is provided below.

From the above code, you will see that I am checking if the clicked item has its id in the Content Event Click container. If it is not present, the click will not be registered in MongoDB.

Once the data has been captured in MongoDB, you will need to implement an aggregator which will aggregates the data from MongoDB to the Sitecore Reporting Database. You can read more from my blog post on How to setup the Sitecore Aggregation.

Note:

You will need to have a custom table to add those data.

Implement a dashboard or page on the Sitecore Experience Analytics Page to read the data.

]]>https://hishaamn.wordpress.com/2018/05/17/sitecore-click-stream-analytics/feed/0Sitecore Analytics vs Google AnalyticsnhishaamTrackOBwz9.pngSitecore Database Agenthttps://hishaamn.wordpress.com/2018/04/25/sitecore-database-agent/
https://hishaamn.wordpress.com/2018/04/25/sitecore-database-agent/#respondWed, 25 Apr 2018 07:02:11 +0000http://hishaamn.wordpress.com/?p=3751From my last few posts, I have been talking about the Sitecore Tasks. Using the Sitecore Tasks allow a user to either set the task as synchronous or asynchronous. It is the Sitecore.Tasks.DatabaseAgent which runs at a define interval and loops through the container /sitecore/system/tasks/schedules.

When jobs are being executed, if it is synchronous, the entry in the jobs.aspx page will be as Master_Database_Agent (5 of 7). This means that of the 7 jobs that has been scheduled, it is at the 5th task.

What is the 4th, 5th or 7th task?

Right now, we don’t know which task is being executed unless we go and check the logs. You just need to make sure that the logger level is INFO. This is a Sitecore out of the box functionality.

But from a usability perspective, you will want to have the name of the task being executed when you check the jobs.aspx page. I will be explaining on how you can add the name of the task to the jobs.aspx page.

First, you need to extend the current Tasks.DatabaseAgent class.

The main change in the code is at line 41. The change will only apply for synchronous tasks.

Lastly, you need to update the config file to make Sitecore use the new method you implemented.

]]>https://hishaamn.wordpress.com/2018/04/25/sitecore-database-agent/feed/0image(1)nhishaamSitecore – Who triggered that task?https://hishaamn.wordpress.com/2018/04/09/sitecore-who-triggered-that-task/
https://hishaamn.wordpress.com/2018/04/09/sitecore-who-triggered-that-task/#commentsMon, 09 Apr 2018 19:27:49 +0000http://hishaamn.wordpress.com/?p=3748Following recent Sitecore versions, we have seen that Sitecore has integrated the Job.aspx page which is found under the admin folder. This is very useful to content authors, developers because it helps to see what current tasks are being executed. However, for me, I see a missing feature: Who has triggered that task?

I was recently performing some performance tuning on our servers and we sent a mail to everyone asking them not to trigger any agents. All scheduled agents are disabled. Yet, I could see different agents being triggered on the server and this was impacting my testing.

From the previous Sitecore Job page that we most have used, we were able to see who has triggered the task but from the newer versions, this has been omitted. So, if you want to know how to be able to see who triggered the task, please continue to read the article.

Override Existing Sitecore Job Page

JobsExtension.aspx

To achieve this, I have created a new .aspx page in the admin folder named JobsExtension.aspx. In that file, I have copied and pasted the existing markup of the Job.aspx page but only changing the signature in the header, i.e, the CodeBehind and Inherits attributes.

CodeBehind

Coming to the back-end code, I have my class inherits the existing Jobs class from the namespace Sitecore.ExperienceContentManagement.Administration. I had to override the following methods

OnLoad(EventArgs e)

ShowJobs(StringBuilder stringBuilder, string name, ICollection jobs)

ShowRefreshStatus(StringBuilder stringBuilder)

OnLoad

You need to override the OnLoad method since we need to make the new Job Extension to use our OnLoad instead of the base one.

ShowJobs

In the ShowJobs method, you need to append a new table data named Owner and then for each job, you need to set the context user. Note that it may be the case that the Context user is null. So, make sure that you check for null. Below is the code for the ShowJobs method.

ShowRefreshStatus

You need also to update the ShowRefreshStatus method for it to use the new job extension page. Below is the code snippet of the update.

You can use the above code and customize it for your own requirement. If you want to use it as is, you can install the Sitecore package found here.