API
Version 7.x > API > Get Parent Document Data on Document Creation View modes: 
User avatar
Member
Member
pzill4 - 12/26/2013 1:41:55 PM
   
Get Parent Document Data on Document Creation
I have a bunch of custom form controls and I want to control the display by being able to decide what data the parent document the current document is trying to be created under.

Is there a way to view the parent document data prior to saving a new document?

User avatar
Member
Member
pzill4 - 12/26/2013 1:44:54 PM
   
RE:Get Parent Document Data on Document Creation
pzill4 wrote: I have a bunch of custom form controls and I want to control the display when creating children documents by being able to decide based on parent document data.

Is there a way to view the parent document data prior to saving a new document?


User avatar
Member
Member
kentico_sandroj - 12/26/2013 2:59:36 PM
   
RE:Get Parent Document Data on Document Creation
Hello,

One approach would be to use a custom handler which would give you access to all of the data before saving. Would this work for you?

Best Regards,
Sandro

User avatar
Member
Member
pzill4 - 12/26/2013 7:47:04 PM
   
RE:Get Parent Document Data on Document Creation
Thanks

I also found that in the CMSContext.URL property, there is a parentid query param that would do it as well.

None were tested, but I think you've managed to give me 3 options.


User avatar
Kentico MVP
Kentico MVP
Brenden Kehren - 12/27/2013 6:25:10 AM
   
RE:Get Parent Document Data on Document Creation
Be careful which "option" you use as you could come up with unexpected results.
CMSContext.CurrentDocument.Parent
will return the parent of the document you are navigating to.
Eval("NodeParentID")
Will return the parent ID of the document being rendered at that time, most likely used in a transformation.  

User avatar
Kentico MVP
Kentico MVP
Brenden Kehren - 12/26/2013 3:01:13 PM
   
RE:Get Parent Document Data on Document Creation
Using a macro, you can access the parent like so
{% CMSContext.CurrentDocument.Parent.<propertyname>%}

User avatar
Kentico MVP
Kentico MVP
Brenden Kehren - 12/26/2013 3:07:22 PM
   
RE:Get Parent Document Data on Document Creation
You can also use something like this in code behind{code]CMS.DocumentEngine.TreeProvider tree = new CMS.DocumentEngine.TreeProvider();
CMS.DocumentEngine.TreeNode parentNode = tree.SelectSingleNode(CMS.CMSHelper.CMSContext.CurrentDocument.NodeParentID);
[/code]