Sitecore Items – Get Keyword Reference Items

Challenge:

We need to know in how many Sitecore items word “keyword” is present. This requirement arrived because client had a contract with one third party service and now they have planned to discard the contract with that party and change the service with other party. Now these third party services provide some script which we add in Sitecore item and now for all the items where we have script used by first service need to be replaced with another. And the site is very big and we can’t check each and every item where the “keyword” is present.

So after discussing with Urvesh, we came up with an idea to fetch from Database directly.

001

Solution:

Ultimately sitecore stores the value in Database into three tables — Versioned, Unversioned and Shared fields. So we wrote a query which will hit all the three tables and provide us the item ids where the keyword is present. The site is in many languages and if in any language version the keyword is present then it will be captured. This saved enormous time and money. :) We’ve heavily used this utility for providing the report to the Content Authors and Migration. Additionally we have created many such tools which can update the items in bulk, we will share it soon.

Database Queries:

1) Versioned Fields
var query = @”Select [ID], [Name] FROM [dbo].[Items]
Where [ID] in (Select DISTINCT [ItemId] From [dbo].[VersionedFields] Where [FieldId] in (SELECT [ID] FROM [Items] Where Name NOT LIKE ‘\_\_%’ ESCAPE ‘\’) AND Value like ‘%” + strKeyword + “%’)”

2) Shared Fields
var query = @”Select [ID], [Name] FROM [dbo].[Items]
Where [ID] in (Select DISTINCT [ItemId] From [dbo].[SharedFields] Where [FieldId] in (SELECT [ID] FROM [Items] Where Name NOT LIKE ‘\_\_%’ ESCAPE ‘\’) AND Value like ‘%” + strKeyword + “%’)”

3) Unversioned Fields
var query = @”Select [ID], [Name] FROM [dbo].[Items]
Where [ID] in (Select DISTINCT [ItemId] From [dbo].[UnversionedFields] Where [FieldId] in (SELECT [ID] FROM [Items] Where Name NOT LIKE ‘\_\_%’ ESCAPE ‘\’) AND Value like ‘%” + strKeyword + “%’)”

We wrote an aspx code file and deployed on the server. This utility will provide us the report which we can export easily.

Download: Click Me (Right click and Save Link As)

Screenshot:

GetKeyWordReferenceItems

Thanks to Urvesh who worked on this!
Let us know if you have found any other solution.

Happy Sitecoring! :)

Share

Read More

Sitecore Module – Delete Multiple Items

Delete Multiple Items – A module for Content Authors to Delete Multiple Items.

Sitecore 7.0 Sheer UI – ASPX Application
Sitecore 8.2 Speak UI

A Module for deleting Multiple Sitecore Items. This application was built first as an ASPX page (You can access it with /sitecore/admin/DeleteMultipleItems/DeleteMultipleItems.aspx), then provided an option in Sitecore Start Menu which can be used as an application as shown in screenshot. After that I learnt and explored Speak application via Knockout JS and then built a new application based on SPEAK UI which can run on Sitecore 8.2. Download the package based on the Sitecore version in which you are going to install.

Download it from Sitecore Marketplace

Documentation: GitHub

Source Code: GitHub

Well, If you are working on your DEV Machine, then you can easily delete multiple items with the help of Sitecore Rocks. Refer: http://www.sitecore-cms.de/2013/12/how-to-delete-more-than-one-item-in.html

Output:

Delete Multiple Items
Delete Multiple Items – Sheer UI
Delete Multiple Items
Delete Multiple Items – Speak UI

 

Thanks to my friend – Vikram for blogging the very good series of articles for SPEAK application. Thsi helped in gaining basic knowledge about Sitecore Speak application.

Share

Read More

Sitecore Module – Sitecore Child Item Count

Sitecore Child Item Count Module is for getting the child item of the selected item in Content Editor. It also provide an option to specify the template id of child item, if you want to fetch the items of any specific template. It works based on the index. It also check the current Language. If your current selected language is Japanese and if the child item doesn’t exist with Japanese language version than it won’t include in child count.

For more information: Documentation

Download it from – Sitecore Marketplace

Source Code: GitHub

Share

Read More

Sitecore query with hypen or dashes

Challenge:

Sometimes your sitecore query might contains hypen or space and you get an error: “unterminated literal string in Query”. It is because the query contains an illegal character and the solution is to escape the “-“.So we need to add hash(#) around the word in the query.

Query: /sitecore/content/My Site/Event/ABC-Items

Earlier I referred the below article and implimented in one of the project:

Escaping dashes/“-” in Sitecore Queries. Datasource query Update

This is actually the nice example. But while working on another project, I applied below piece of code which I think is better and easy solution then the one given in above link.

Solution:


StringBuilder startItemPath = new StringBuilder(@"/");
startItemPath.Append(string.Join("/", myItemsFolder.Paths.FullPath.Split(new char[] { '/' },
StringSplitOptions.RemoveEmptyEntries).Select(x => string.Format("#{0}#", x))));

allItems = contextDb.SelectItems("fast:" + startItemPath + "//*[@@templateid = '" + templateID + "']").ToList();

By applying above solution. The query will contain “#” around all the words in query. It won’t create any harm for the query to execute.

If you know any other better approach then do comment below.

Happy Querying!

Share

Read More

Sitecore Experience Editor with different Site context

Challenge:

In Multi-Site Sitecore solution we allow user to load any site in Experience Editor with any Sitecore Site URL. We also provide an option to the user to create Sites on the fly. The problem we were facing was during Experience Editor. In Experience Editor you can make use of query string and get the Item based on sc_itemid. That was working absolutely fine. Now we provided an option to a user in Ribbon to change the color. Every Custom Site that user creates on the fly – each have their own fields to change the color.  We were not getting the correct site because Webutil was providing the below information.

Sitecore.Web.WebUtil.GetRawUrl(): “/-/speak/request/v1/expeditor/ExperienceEditor.GenerateFieldUrl”

Speak Request URL: http://sc8.com:80/-/speak/request/v1/expeditor/ExperienceEditor.GenerateFieldUrl

Now in this request you don’t get sc_itemid – we wanted to get the actual item id (sc_itemid) based on the current Site which user has loaded in Experience Editor, so that we can show/load the correct option to change the color.

(more…)

Share

Read More

Error: Could not load file or assembly Ninject

Challenge:

Error: Could not load file or assembly ‘Ninject, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7’ or one of its dependencies. The system cannot find the file specified.

Above error started appearing suddenly in our local Sitecore (Sitecore.NET 8.1 (rev. 151207)) project. We eyed lot of articles on-line but none helped, So that is why I thought it’s better to blog this out. We investigated for couple of hours to get this fixed, may be this post saves someone’s time.

(more…)

Share

Read More

Sitecore – CopyTo() not working?

Are you getting the below error while copying Sitecore Media Item(s) from one node to another. For example – from Canada Site to Australia Site?
13664 19:28:32 ERROR Project.WCMS.Extension.Shell.Applications.CopyProductData.SitecoreExtensions.CopyField: Error while saving copiedMediaItem in Copy Product Data Wizard [System.InvalidOperationException: An instance of Sitecore.Data.Items.Item was null. Additional information: Failed to find the root item "/".
at Sitecore.Diagnostics.Assert.IsNotNull(Object value, String message)
at Sitecore.Web.UI.HtmlControls.DataContext.GetState(Item& root, Item& folder, Item[]& selected)
at Sitecore.Web.UI.HtmlControls.DataContext.GetState(Item& root, Item& folder)
at Sitecore.Web.UI.HtmlControls.DataContext.ItemCreatedNotification(Object sender, ItemCreatedEventArgs args)
at Sitecore.Data.Events.ItemCreatedDelegate.Invoke(Object sender, ItemCreatedEventArgs args)
at Sitecore.Events.Event.RaiseItemCreated(Object sender, ItemCreatedEventArgs args)
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at Sitecore.Data.Engines.DataEngine.RaiseCreated(EventHandler`1 handlers, Item item, SafeDictionary`2 visited)
at Sitecore.Data.Engines.DataEngine.DataEngine_CopiedItem(Object sender, ExecutedEventArgs`1 e)
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at Sitecore.Data.Engines.EngineCommand`2.RaiseEvent[TArgs](EventHandler`1 handlers, Func`2 argsCreator)
at Sitecore.Data.Engines.DataCommands.CopyItemCommand.Executed()
at Sitecore.Data.Engines.EngineCommand`2.Execute()
at Sitecore.Data.Engines.DataEngine.CopyItem(Item source, Item destination, Boolean deep, String copyName, ID copyId)
at Sitecore.Data.Managers.ItemProvider.CopyItem(Item source, Item destination, Boolean deep, String copyName, ID copyId)
at Sitecore.Data.Managers.ItemManager.CopyItem(Item source, Item destination, Boolean deep, String copyName, ID copyId)
at Project.WCMS.Extension.Shell.Applications.CopyProductData.SitecoreExtensions.CopyField(Item item, Field sourceField) in \Project.WCMS.Extension\Shell\Applications\CopyProductData\CopyProductDataWizard.cs:line 982]

(more…)

Share

Read More

Sitecore Executive Dashboard Error: An error occurred while loading report data. Please try again or contact your administrator.

Are you getting the below exception in Executive Insight Dashboard then this post is for you.

1. Error

Executive Insight Dashboard isn’t loading data at all. This was happening with us when we were accessing production analytics data. There was no any message in Logs. It was very confusing for us because you have no clue what is happening without logs.  (more…)

Share

Read More