Can't retrieve column values in GetDocuments Query

Tom F asked on January 4, 2017 01:53

Hi I'm trying to get the value of some properties retrieved using CMS.DocumentEngine.DocumentHelper in Kentico v10

I've tried:

var test1 = CMS.DocumentEngine.DocumentHelper.GetDocuments("ImageWithDescriptionGrid").OnCurrentSite().Columns("AppliesToPages").FirstOrDefault();

var test2 = CMS.DocumentEngine.DocumentHelper.GetDocuments().Type("ImageWithDescriptionGrid", q => q.Columns("AppliesToPages")).FirstOrDefault();

and then

test1.GetValue("AppliesToPages");

and

test2.GetValue("AppliesToPages");

and they always return null test1.ContainsColumn("AppliesToPages"); returns true as does test2.ContainsColumn("AppliesToPages");

Where the field type is a Pages type.

I was hoping someone could assist.. Even simple string properties don't work either way..

Thanks, Tom

Recent Answers


Roman Hutnyk answered on January 4, 2017 10:06 (last edited on January 4, 2017 10:06)

Call WithCoupledColumns() query method like this:

DocumentHelper.GetDocuments()
                            .Type("CMS.News")
                            .Path("/News", PathTypeEnum.Children)
                            .OnSite("CorporateSite")
                            .WithCoupledColumns();

See more examples here.

1 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on January 4, 2017 16:04 (last edited on January 4, 2017 16:28)

Not quite sure that I understand what you want. I assume you want to get the list of values:

var rowArray = DocumentHelper.GetDocuments("ImageWithDescriptionGrid").Column("AppliesToPages")
.WhereEquals("SomeColumnName", 123).Result
if (!DataHelper.DataSourceIsEmpty(rowArray))
{
    string MyValues =  TextHelper.Join(",", DataHelper.GetStringValues(rowArray.Tables[0], "AppliesToPages"))
}

Or for single value:

  var node = DocumentHelper.GetDocuments("ImageWithDescriptionGrid")
                .Column("AppliesToPages")
                .WhereEquals("SomeColumnName", 123)
                .FirstObject;
 string MyValue = ValidationHelper.GetString(node.GetValue("AppliesToPages"), "");             
0 votesVote for this answer Mark as a Correct answer

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