Using Macro in Default Value for a page type field

Thomas Seyssens asked on August 8, 2016 14:44

i want to know if you can use a macro to fill in a default value for a field. For example, we have a subpage, that needs the same picture as the parent page. How can we do this without filling it in manually all the time?

Page structure:

  • parent page
    • Sub page

Field Type: Long Text (custom image selector)

Recent Answers


Jan Hermann answered on August 8, 2016 14:57 (last edited on August 8, 2016 20:00)

Well, it depends on a form control that is used on your parent, but the value is possible to get like this:

{%EditedObject.Parent.GetValue("imagefield")%}

0 votesVote for this answer Mark as a Correct answer

Thomas Seyssens answered on August 8, 2016 15:04

Hi Jan,

Didn't really do the trick.. It returns nothing in the field when making a new item. Any other ideas?

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on August 8, 2016 15:07

Clone the bizform webpart and then create an onbefore save event, and set your field = to the other image field.

bizform.MyOtherField = bizform.FirstField;

Then the form will save both having the same value.

0 votesVote for this answer Mark as a Correct answer

Dawid Jachnik answered on August 8, 2016 15:50

Hi,

Both pages parent and sub page has the same field type and form control ?

Try with EditedObject

{% EditedObject.Parent.GetValue("imagefield") %}
0 votesVote for this answer Mark as a Correct answer

Thomas Seyssens answered on August 8, 2016 16:33

Hello,

yes, they have the same field & fieldType. I tried your solution, but that doesn't seem to work..

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on August 8, 2016 20:01 (last edited on August 9, 2016 08:59)

Try this:

{%Documents[EditedObject.Parent.NodeAlaisPath].GetValue("imagefield")%}

and make sure you enter the macro via the macro editor (small black triangle next to the property)

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on August 9, 2016 12:45

You can access any field in the hierarchy like this

{%CMSContext.CurrentDocumentParent.ImageField#%}

In case the field is parent of a parent then you can extend like this

{%CMSContext.CurrentDocumentParent.Parent.ImageField#%}

Try this and let me know.

Please check Macros Debug to see if you are getting any error

Cheers, CHetan

2 votesVote for this answer Mark as a Correct answer

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