Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Retrieve Parent Node values using current NodeID in transformation View modes: 
User avatar
Member
Member
Jimmy - 2/28/2011 6:12:35 PM
   
Retrieve Parent Node values using current NodeID in transformation
Hi

I need to combine 2 values from the parent node of a node in a transformation.

I've tried writing a custom transformation which I can't get to work. Is that the only way I can retrieve those values?

I keep getting the following error from my custom function:
error CS1502: The best overloaded method match for 'MyWFunctions.getPackageBuilder(int)' has some invalid arguments

Here are my 2 functions:


/// <summary>
/// Returns the closest ancestor node with the specified classname
/// </summary>
/// <remarks>
/// Will start by checking the node of the node id supplied
/// </remarks>
public static CMS.TreeEngine.TreeNode getClosestAncestorOfClass(int nodeID, string className){
CMS.TreeEngine.TreeNode nCurNode = TreeHelper.SelectSingleNode(nodeID);
if (nCurNode != null)
{
// begin looping up the tree (safeguard stop at the root)
while (nCurNode.NodeClassName != "CMS.Root"){
if (nCurNode.NodeClassName != className){
nCurNode = TreeHelper.SelectSingleNode(nCurNode.NodeParentID);
} else {
return nCurNode;
}
}

}

// fall back on returning a null/empty node
return TreeHelper.SelectSingleNode(0);

}


/// <summary>
/// Returns the builder logo and name from parent node of package
/// </summary>
/// <param name="packageNodeID"></param>
/// <returns>Some HTML with the logo and Name of builder to fi in Transformation
/// </returns>
public static string getPackageBuilder(int packageNodeID){
string result = "";
string bName = "";
string bLogo = "";


CMS.TreeEngine.TreeNode packageNode = TreeHelper.SelectSingleNode(packageNodeID);
if (packageNode != null && packageNode.IsPublished)
{
// get the Builder node
CMS.TreeEngine.TreeNode builderNode = MyWFunctions.getClosestAncestorOfClass(packageNodeID, "Warralily.HLBuilder");
if (builderNode != null && builderNode.NodeClassName == "Warralily.HLBuilder")
{
bName = builderNode.DocumentName;
//bLogo = builderNode.BuilderLogo;
bLogo = "/img/v4/1px.gif";
}
else
{
bName = "Builder";
bLogo = "/img/v4/1px.gif";
}


result = "<img src=\"" + bLogo + "\" width=\"130\" height=\"45\" alt=\"" + bName + "\" /></div><div class=\"builder\"><b>" + bName + "</b>";

}

return result;
}



I think I am on the right track, I just can't get it to work.

Any help would be much appreciated.

James


User avatar
Member
Member
Chanan - 3/1/2011 5:56:35 AM
   
RE:Retrieve Parent Node values using current NodeID in transformation
The error message seems to indicate that you are not calling your function correctly. Can you show the calling code?

Are you sure you are calling your function with an int? Try wrapping your function with: Convert.ToInt32() - Or better yet, for testing purposes, just call your function with a known NodeID.

User avatar
Member
Member
kentico_michal - 3/8/2011 2:09:41 AM
   
RE:Retrieve Parent Node values using current NodeID in transformation
Hi James,

I tested your code and I have not received any error message. So as Chanan has already mentioned it really seems that you are trying to invoke this method incorrectly. Could you please post here the code from your transformation where you call this method?

Moreover, the idea of getting parent node’s values using custom transformation is correct, because it is impossible to get these values directly in transformation.

Best regards,
Michal Legen