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"] |(user)zbynekh|(hash)739e655fe11c1cf128092cf8448e6f63e257a167f61d9479f02d7ce041db426d%}

You MAY need to also do this for custom fields {% Documents.WithAllData.Where("NodeGUID='" + CurrentDocument[ "RelatedCollection" ] + "'")[0]["Collection_desc"] |(user)zbynekh|(hash)5dbde199aa0b028dd4e529ac591364cf1c3f98b4dab495fa734f196515bddb84%}

1 votesVote for this answer Unmark Correct answer

Recent Answers


Marcel Guldemond answered on April 4, 2016 20:55 (last edited on March 24, 2018 12:15)

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 |(user)zbynekh|(hash)02cf8a8522f718d777fe657d24c434f7c5f5470acf43c93fea036eb63921d533%}

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on April 4, 2016 20:56 (last edited on March 24, 2018 12:15)

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")|(user)zbynekh|(hash)f2b86a050bd734fab4bb8a68c33de34af1d5d0a1a83067c64006490b9a6d901d%}

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.