Issue with DocumentHelper.GetDocuments() not returning properties

Pedro Graca asked on February 15, 2016 15:30

Hi,

It seems I am experiencing some issues getting the properties (fields) of a document using DocumentHelper.GetDocuments().

As an example:

var docs = DocumentHelper.GetDocuments()
                        .OnSite(SiteContext.CurrentSiteName)
                        .Path(rootPath, PathTypeEnum.Children)
                        .Culture("en-GB")
                        .CombineWithDefaultCulture(true)
                        .Published(true)
                        .NestingLevel(3)
                        .ExcludePath("/Products", PathTypeEnum.Section)
                        .Where("NodeID <> " + rootNode.NodeID + ")
                        .OrderBy("NodeLevel")
                        .OrderBy("NodeOrder");

foreach (var doc in docs)
{
    doc.GetValue("MenuItemGroup") //THIS IS NULL
    DocumentHelper.GetDocument(doc ,new TreeProvider()).GetValue("MenuItemGroup") //DISPLAYS CORRECT VALUE
    doc.GetValue("MenuItemGroup") //IT NOW DISPLAYS CORRECT VALUE
}

Obviously, I want to avoid unnecessarily making another call.

Could you please advise?

Thank you, Pedro

Recent Answers


David te Kloese answered on February 15, 2016 16:14

Hi,

Can you try including the columns property:

.Columns("MenuItemGroup", "SomeMorecolumn", "anotherColumn");

Greets,

David

0 votesVote for this answer Mark as a Correct answer

Pedro Graca answered on February 15, 2016 16:49

Hi David,

Unfortunately, it doesn't work.

DataConnection.HandleError]: Caused exception: Invalid column name 'MenuItemGroup'.

Thank you, Pedro

0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on February 15, 2016 17:07

I think you might have to include a classname. DocumentHelper.GetDocuments("classname")

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on February 15, 2016 17:12

If you need multiple types you can use:

types:

.Types("CMS.News", "CMS.SimpleArticle")

You can also find some more info here:

http://devnet.kentico.com/articles/kentico-8-technology-documentquery-api

David

0 votesVote for this answer Mark as a Correct answer

Pedro Graca answered on February 15, 2016 17:41

Hi David,

Thank you for your help, but even including all the types that I need (which seems counter intuitive) the result is the same.

Thank you,

Pedro

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 15, 2016 22:49

Problem is coupled data is not included with the GetDocuments().Types("cms.menuitem", "cms.event") method. You can get coupled data with this method GetDocuments("cms.menuitem"), problem is you can only include one type in that query.

Check out this post and about half the way down there is some info on "Multiple document types data".

1 votesVote for this answer Mark as a Correct answer

Pedro Graca answered on February 25, 2016 00:25

Hi everyone,

Not the most elegant way of approaching this issue but it may help someone. Effectively what I had to do was append the different page types.

Undoubtedly this is far from dynamic as I will need to add more ".Type's" to the query if I am to include further page types.

Here is a sample of the code

  nodes = DocumentHelper.GetDocuments()
                .Type("CMS.MenuItem", q => q.Columns("MenuItemGroup").WhereLike("MenuItemGroup", "%" + menuType + "%"))
                .Type("xxx.1", q => q.Columns("MenuItemGroup").WhereLike("MenuItemGroup", "%" + menuType + "%"))
                .Type("xxx.2", q => q.Columns("MenuItemGroup").WhereLike("MenuItemGroup", "%" + menuType + "%"))
                .Type("xxx.3", q => q.Columns("MenuItemGroup").WhereLike("MenuItemGroup", "%" + menuType + "%"))
                .Type("xxx.4", q => q.Columns("MenuItemGroup").WhereLike("MenuItemGroup", "%" + menuType + "%"))
                .Type("xxx.5", q => q.Columns("MenuItemGroup").WhereLike("MenuItemGroup", "%" + menuType + "%"))
                .OnSite(SiteContext.CurrentSiteName)
                .Path(rootPath, PathTypeEnum.Children)
                .Culture("en-GB")
                .CombineWithDefaultCulture(true)
                .Published(true)
                .NestingLevel(nestingLevels)
                .ExcludePath("/Products", PathTypeEnum.Section)
                .Where("NodeID <> " + rootNode.NodeID + " AND ClassName <> 'CMS.Product' AND DocumentMenuItemHideInNavigation = 0")
                .....

Best regards, Pedro

0 votesVote for this answer Mark as a Correct answer

Tim G. answered on November 18, 2016 12:28

I've been trying to do something similar to this and even following this post (http://devnet.kentico.com/articles/kentico-8-technology-documentquery-api) I still can't get this work.

For example if I have something like the below I still get a data-binding error that the property for MenuItemName does not exist:

var docs = DocumentHelper.GetDocuments() .Type("Namespace.Type", q => q.Columns("MenuItemName")) .Type("Namespace.Type", q => q.Columns("MenuItemName"));

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.