Custom field not displaying using macro as default value

Tomasz Sikora asked on September 8, 2017 11:57

When I'm creating new content-only page, I want to set default value of one field based on value from other field. Image Text

I have the following macro {% EditedObject.FirstName #%} for my AltText field

Image Text

Macro editor detects FirstName property, but when I'm creating new page, this field contains only "picture" in it and macro seems to be not resolved or empty. I also set "Depends on another field" for AltText and HasDependingFields on FirstName.

Is there anything more I need to do to make this work? What I want is to update AltText property to be "[FirstName] + picture" each time FirstName will change and optimally if it's possible to not update it when AltText was changed manually but I think it works like that by default.

Recent Answers


Peter Mogilnitski answered on September 8, 2017 12:58 (last edited on December 10, 2019 02:31)

You probably need to revise your logic about alt field,i.e. when you form image tag for example in a transformation you can put there the default logic {%CurrentDocument.AltText ==""?CurrentDocument.Name +" picture":CurrentDocument.AltText|(identity)GlobalAdministrator%}. So essentially alt text will be empty except special cases.

1 votesVote for this answer Mark as a Correct answer

Suneel Jhangiani answered on September 8, 2017 14:38

I'd go with Peter's suggestion.

However, have you set the 'Has Depending Fields' on the FirstName field and the 'Depends on other fields' for the AltText? This would cause a postback when the firstname changes.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 8, 2017 16:16 (last edited on December 10, 2019 02:31)

The proper syntax for the macro is

{%EditedObject.FirstName.Value|(identity)GlobalAdministrator%}

As somewhat explained in the previous answers, this won't always work, because on saving of the data, the macro may not know what the value is until later in the process. So best thing to do is as Suneel suggests, and set the Has depending fields on the FirstName field and Depends on other fields for the AltText. This will cause the postback and allow the AltText to populate with the FirstName value

3 votesVote for this answer Mark as a Correct answer

Tomasz Sikora answered on September 11, 2017 09:18 (last edited on December 10, 2019 02:31)

Thank you for suggestions. Unfortunately it doesn't work. As I said in my initial post, I had has dependin fields on "FirstName" and depends on another field on AltText. Postback works but alt text is not updated. The macro displays only static part " picture". The macro provided by Brenden Kehren doesn't do the job either. (Value property is not detected by auto completion in macro editor)

{%EditedObject.FirstName.Value|(identity)GlobalAdministrator%}

I think It might not be possible and I really need to rethink my logic on this field as Peter suggested.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 11, 2017 13:51

Just because the Value property is not auto detected doesn't mean it won't work. The proper way to access a field's value is to use FieldName.Value not FieldName. FieldName is the object.

1 votesVote for this answer Mark as a Correct answer

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