New document to have property Field populated based on the parent node

raymond amegadjin asked on August 20, 2014 15:54

Hi, Im trying to pre-populate certain fields of a document type based on its parents to avoid re-typing them. i.e: Region (Parent) has the following fields populated Country and Region name. It's child Shop must have his field region qnd country pre-populated when creating a new shop based on the info found on it's parent.

I've tried achieving this result with the following Macro : {% CMSContext.CurrentDocument.Parent.GetValues("CountryName") %} or {% DocumentContext.CurrentDocumentParent.GetValue("CountryName") %} But both failed.

Correct Answer

Jan Hermann answered on September 15, 2014 10:17

Hello,

you should be able to access the parent object on the Form tab as:

EditedObject.Parent.Field

or parent of parent like:

EditedObject.Parent.Parent.Field

Best regards,
Jan Hermann

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on August 20, 2014 20:38

Why would you need that populated if its already defined in the hierarchy? Depending on what version you are using it will vary what you use. Also, when are you attempting to populate this data?

0 votesVote for this answer Mark as a Correct answer

raymond amegadjin answered on August 29, 2014 15:30

Hi Brenden,

My goal is to populate the Location field of the Google Basic Maps based on a concatenation of both the parent node property and the child. Because in my scenario the GPS coordinates are not all the time available. Unfortunately this approach sseems not to be the best .May you find below the recommendation from the support team

Unfortunately this approach will not work because the macro is not resolved in the context of the current document and also its resolved before the document is created. There is another approach - You can create a global event -> Document.Insert.After which would automatically set your field to a parent name. You would get the parent node form the NodeParentID property of the edited object.

Its quite easy to accomplish - please see following article about global events. It also features a simple example from which you can inspire: docs.kentico.com/display/K8/Handling+global+events

0 votesVote for this answer Mark as a Correct answer

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