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 March 24, 2018 12:15)

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

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 March 24, 2018 12:15)

Hi,

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

Try with EditedObject

{% EditedObject.Parent.GetValue("imagefield") |(user)zbynekh|(hash)dc79eb0b9915298633aa5e791c7ed8fdd61de37180c6398b923dd864b93d57fa%}
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 March 24, 2018 12:15)

Try this:

{%Documents[EditedObject.Parent.NodeAlaisPath].GetValue("imagefield")|(user)zbynekh|(hash)1875421b4b747adfc08ae9a84bc0fc2dcdf0d457c54e85d0baca283f54aed25f%}

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 March 24, 2018 12:15)

You can access any field in the hierarchy like this

{%CMSContext.CurrentDocumentParent.ImageField|(user)zbynekh|(hash)d3a200e8f14f9b4341eae9da1338821e34120fd3b063dcc7c7b29379c8bdedb8%}

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

{%CMSContext.CurrentDocumentParent.Parent.ImageField|(user)zbynekh|(hash)b7ae847c2cd4c326bd91deb4c8f4f4117fd90e5d6646a357901c402c6147e662%}

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 March 24, 2018 12:15)

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

{% Documents["/" + CurrentDocument.NodeAliasPath.Split("/")[1]].GetValue("MyField") |(user)zbynekh|(hash)5489019d020c9de31c78a64233e81c6027e1bbae318ec3655674a2013428f295%}

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.