2

I have had a to get child items in a tree where their name contains a value. This was working until I updated the node (and its templates) to be a bucket. Now I can't get the query to return anything.

I have the item with item name "myItem-123" in the bucket. Typing "123" in the bucket search in the client UI returns the item just fine. "clients" is the bucket in the tree.

var getItemBuilder = new GetItemByPathBuilder()
            .Path("/sitecore/content/Client Content/Global/Settings/clients//*")
            .AddParam($"123");

        var clientSetting = this.contentRepository.GetItem<IMyInterface>(getItemBuilder.Options);

I can use this XPath in XPath builder and it returns the time (I have to use the full name but even with the full name in the addparam call I still get nothing).

I had this all setup and working before I changed it to an item bucket. Not sure how the item bucket change would have broken this. Am I not understand the "AddParam" method correctly?

I have tried a number of GetItems method and GetItemsOptions that match other queries I have done and all those fail as well. It seems whatever I try to query items in a bucket fails.

var getItems2 = new GetItemsByQueryOptions(new Query("/sitecore/content/Client Content/Global/Settings/clients/*"));

var test2 = this.contentRepository.GetItems<IClientViewTemplate>(getItems2);

This also errors out saying the operation is not supported

My mapping looks like this.

this.Map(
            config =>
            {
                config.AutoMap();
                config.TemplateId("MyTemplateGUId");
                config.EnforceTemplateAndBase();
                config.Field(x => x.ViewTemplate).FieldId("MyFieldGUID");
            });
1
  • Not really an answer, but you shouldn't be using sitecore queries to get results like this. If you have a bucket and you need to get a result, best practice dictates that you handle this using the Content Search API instead. Mostly because you are using a recursive query to get your results which if there ends up being thousands of items in your bucket (which is why you typically use a bucket) your results could take an extended time to return. – Dylan Young Feb 6 '19 at 21:54
1

Here is the solution I found. I need to play more with the AddParams method as I don't fully understand what that is doing. I got the query to work with the below code (if there is a better way please let me know) and wanted to post in case it could help anyone else.

var getItems = new GetItemByQueryBuilder()
                .Query($"<rootPath>//*[contains(@@name,'{myParam.ToLower()}')]");
var mySetting = this.contentRepository.GetItem<IMyTemplate>(getItems.Options);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.