Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Getting a Parent ID View modes: 
User avatar
Member
Member
Jason - 3/21/2011 4:33:21 AM
   
Getting a Parent ID
Hi all,
I have created 3 types of Custom Document.
Country
Resort
Hotel

They are in a hierarchy With country at the top and Hotel at the bottom
so:
Country
¬
Resort
¬
Hotel

Every is fine, but when I insert a Resort or a country
I would like to be able to get the Primary Key for the parent and insert it in to the child.

Example:
User creates a new resort under a country and in the background the parent countryID is inserted into the Resort table "ParentCountryID"

Thanks for any help

Jason

User avatar
Member
Member
Chanan - 3/21/2011 9:19:20 AM
   
RE:Getting a Parent ID
You can get the Parent Node with code like this:

CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider();
CMS.TreeEngine.TreeNode parentNode = tree.SelectSingleNode(nodeId).Parent;


From there you can get the id with a call to GetValue

User avatar
Member
Member
Jason - 3/21/2011 10:19:16 AM
   
RE:Getting a Parent ID
Hi thank you for the help.
I assume this would be a custom handler for
Document Inserted?

Thank you

Jason

User avatar
Member
Member
Chanan - 3/21/2011 10:28:49 AM
   
RE:Getting a Parent ID
Haven't had to use a custom handler yet, but sounds like thats what you need.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 3/21/2011 4:07:13 PM
   
RE:Getting a Parent ID
Hi,

you could set a default value of the Resort document type field (which should contain the parent node id) using a query macro and do not display this field in the form (uncheck Display attribute in the editing form).

The macro should look like:
{%nodeid%}

When the new document is created the parent node ID will be set automatically.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
Jason - 3/21/2011 4:14:13 PM
   
RE:Getting a Parent ID
I GOT TO SAY IT IN CAPS...

I FREAKING LOVE THIS CMS SO FAR!!
.... Im using the trial.... but not for long :) I will be telling the powers that be, that this is the way to go... the only way to go..

Guys well done, this has to be the one of if not the most developer friendly CMS's out there.

Ok back on topic
I used this and it worked very well

Public Overrides Sub OnAfterInsert(ByVal treeNodeObj As Object, ByVal parentNodeId As Integer, ByVal tree As Object)
'INSERT YOUR CUSTOM AFTER-INSERT CODE
Dim NewDocument As TreeNode = treeNodeObj
If NewDocument.NodeClassName = "Mosaicholidays.Resort" Then
NewDocument.SetIntegerValue("ParentCountryID", NewDocument.Parent.GetIntegerValue("CountryID"), False)
End If


End Sub