Sean Holmesby

.NET and Sitecore Developer

By

Multiple Datasource Locations using Queries are back in Sitecore 7.2 Update-2

Sitecore 7.2 Update-2 (rev.140526) was recently released, and one of the entries in the Release Notes was this:-

  • Layouts and renderings
    • The Select the Associated Content dialog did not handle multiple data sources correctly. It only used the first data source and ignored any additional data sources. This has been fixed. (389483)

A while back Thomas Stern wrote a post detailing a way to allow for queries in Datasource locations, so that the Associated Content dialog could be more flexible for multi-site solutions.

I tested out his solution back when the post was written, and it worked perfectly. However I found that it was broken in both Sitecore 7.0 and 7.1.

After getting feedback from Sitecore Support, we determined that the issue was within the SelectRenderingDatasource.xml code. MultiRootTreeview had changed back to a regular TreeviewEx control, meaning that it didn’t know how to handle multiple ‘Datasource roots’.

Sitecore 7.2 Update-2 fixes this, and Sitecore’s default code will allow you to define multiple Datasource locations by having them pipe separated in the ‘Datasource Location’ field on a rendering/sublayout.

01 - Pipe separated locations 02 - Multiple locations using piped locations

This also means that the code Thomas wrote in his blog will work again, as the control will accept multiple Datasource roots again.

I’ve implemented Thomas’ code in this branch of my Launch Sitecore site. (see this commit for the code changes, and this SDN discussion about the code).
I’ve also changed some logic around so that individual queries will be able to return multiple nodes, and that no Root node will show up twice.

        private void ProcessQuery(string query)
        {
 
            Item[] datasourceLocations = ResolveDatasourceRootsFromQuery(query);
            if (datasourceLocations != null && datasourceLocations.Any())
            {
                foreach (Item datasourceLocation in datasourceLocations)
                {
                    if (!DatasourceRoots.Exists(x => x.ID.Equals(datasourceLocation.ID)))
                    {
                        DatasourceRoots.Add(datasourceLocation);
                    }
                }
            }
        }
 
        private Item[] ResolveDatasourceRootsFromQuery(string query)
        {
            string queryPath = query.Replace(_query, ContextItemPath);
            return ContentDataBase.SelectItems(queryPath);
        }

Here is my Datasource Location field.

03 - Pipe separated allowing queries

And now we’re back to the lovely state where Datasources can be selected from multiple dynamic locations.
04 - Multiple locations using a query
Enjoy!

7 Responses to Multiple Datasource Locations using Queries are back in Sitecore 7.2 Update-2

  1. Akshay says:

    Any other ways to set multiple data source in Site core 7.0 version?

    • sholmesby says:

      I have a Sitecore Support DLL (Sitecore.Support.389483.dll) and xml (SelectRenderingDatasource.xml) that enables it. Contact me if you would like it.

  2. Akshay says:

    Thanks for reverting , could you please email me to [email protected]

  3. Akshay says:

    Also I tried to add Thomas’ code from branch of my Launch Sitecore site along with your modified source, when I set query datasource, I get below exception

    Could not resolve type name: <>.SublayoutQueryableDatasource, <> (method: Sitecore.Configuration.Factory.CreateType(XmlNode configNode, String[] parameters, Boolean assert)).

    am I missing something here.??

  4. Waqar says:

    Hi Sholmesby,

    I also need these dll and xml files for Sitecore 7.2 we cannot upgrade it as client wants initial release of Sitecore 7.2 in production which does not include this fix.

    Please send at [email protected]

  5. Syed Ahsan says:

    Hi @sholmesby,
    Thanks for useful comment can you please refer to source for this dll on sdn ? because i also need this dll for 7.2 initial release (rev. 140228).

  6. c0x3y says:

    Just implemented this in our Sitecore 8 build and it looks like it comes for free out of the box

Leave a Reply

Your email address will not be published. Required fields are marked *