How to get document custom field value with macro?

Marcel Guldemond asked on April 4, 2016 20:32

We have a page type for product collections with a number of custom fields added.

I'm trying to get some of the custom field values in a transformation.

The standard document fields like DocumentName and NodeAliasPath show up:

{% Documents.Where("NodeGUID='" + CurrentDocument[ "RelatedCollection" ] + "'")[0].DocumentName %}

( RelatedCollection is a Page Selector field )

but custom fields don't seem to load:

{% Documents.Where("NodeGUID='" + CurrentDocument[ "RelatedCollection" ] + "'")[0].Collection_desc %}

Thanks, Marcel

Correct Answer

Trevor Fayas answered on April 4, 2016 20:45

I believe you just need to put:

{% Documents.Where("NodeGUID='" + CurrentDocument[ "RelatedCollection" ] + "'")[0]["Collection_desc"] |(identity)GlobalAdministrator%}

1 votesVote for this answer Unmark Correct answer

Recent Answers


Marcel Guldemond answered on April 4, 2016 20:55 (last edited on December 10, 2019 02:30)

Great thanks Trevor! It was the WithAllData part that I was missing. This is what worked:

{% Documents.WithAllData.Where("NodeGUID='" + CurrentDocument[ "RelatedCollection" ] + "'")[0].Collection_desc |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on April 4, 2016 20:56 (last edited on December 10, 2019 02:30)

CMSContext.CurrentDocument.GetValue("column","default value") should work for you.

In your particular case it would be something like:

{% Documents.Where("NodeGUID='" + CurrentDocument[ "RelatedCollection" ] + "'")[0].GetValue("Collection_desc ","default value")|(identity)GlobalAdministrator%}

1 votesVote for this answer Mark as a Correct answer

Marcel Guldemond answered on April 4, 2016 22:17

Thanks Roman, but unfortunately the call to GetValue() doesn't seem to work.

0 votesVote for this answer Mark as a Correct answer

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