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 December 10, 2019 02:30)

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")|(identity)GlobalAdministrator%}

1 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 (last edited on December 10, 2019 02:30)

Hi,

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

Try with EditedObject

{% EditedObject.Parent.GetValue("imagefield") |(identity)GlobalAdministrator%}
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 December 10, 2019 02:30)

Try this:

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

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 (last edited on December 10, 2019 02:30)

You can access any field in the hierarchy like this

{%CMSContext.CurrentDocumentParent.ImageField|(identity)GlobalAdministrator%}

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

Stu Furlong answered on September 22, 2017 01:21 (last edited on December 10, 2019 02:31)

I was able to do something similar by applying the following:

{% Documents["/" + CurrentDocument.NodeAliasPath.Split("/")[1]].GetValue("MyField") |(identity)GlobalAdministrator%}

In my case, I wanted to pick a specific (top level) page to inherit a field from. This won't automatically give you the parent page in your structure, but it would allow you to consistently pick a parent no matter how many pages you nest.

Grabbed from an answer on this thread

0 votesVote for this answer Mark as a Correct answer

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