Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Use API to get which column name to use for node alias path and document name View modes: 
User avatar
Certified Developer v6
Certified Developer v6
hoppe - 12/5/2012 9:20:40 AM
   
Use API to get which column name to use for node alias path and document name
I have a custom document type called health article.

When I use the API to create a new document, it does not honor the values I have set for the document name and node alias path in the CMS Site Manager.

How can I retrieve which columns to use for the document name and the node alias using the API?

I thought that the code below would work (using those properties within (DataClassInfoProvider.GetDataClass())), but it does not.
            var tree = new TreeProvider(userInfo);

using (var parentNode = tree.SelectSingleNode(CMSContext.CurrentSiteName, parentNodePath, "##ALL##", true, "CMS.MenuItem", false))
{
if (parentNode == null)
{
return;
}

var dataClass = DataClassInfoProvider.GetDataClass(CustomFunctions.CustomArticle);

if (dataClass == null)
{
throw new Exception("Given document type does not exist.");
}

// Create a new instance of the Tree node
var newNode = TreeNode.New(CustomFunctions.CustomArticle, tree);

var nodeAliasColumn = dataClass.ClassNodeAliasSource;
var nodeAlias = newNode.GetValue(nodeAliasColumn).ToString();
newNode.NodeAlias = nodeAlias;

newNode.DocumentName = newNode.GetValue(dataClass.ClassNodeNameSource).ToString();

try
{
// Insert the document into the content tree
newNode.Insert(parentNode);

Thanks,
Joe Hoppe

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 12/7/2012 2:03:31 AM
   
RE:Use API to get which column name to use for node alias path and document name
Hi,

In your code:

var nodeAliasColumn = dataClass.ClassNodeAliasSource;

newNode.NodeAlias = nodeAlias;



the nodeAliasColumn is just the name of the column, not its data/value. Anyway, this setting is applied automatically. I am using code like this:
// Create an instance of the Tree provider first
TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

// Get the parent node - the API Example folder
TreeNode parentNode = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/home", "en-us");

if (parentNode != null)
{
var dataClass = DataClassInfoProvider.GetDataClass("cms.news");

if (dataClass != null)
{
// Create a new instance of the Tree node
TreeNode newNode = TreeNode.New("CMS.News", tree);

// Set the document's properties
newNode.DocumentName = "My new document";
newNode.DocumentCulture = "en-us";
newNode.SetValue("NewsReleaseDate", DateTime.Now); //required field
newNode.SetValue("NewsSummary", "test summary"); //required field
newNode.SetValue("NewsText", "news text"); //required field
//////////////////////
newNode.SetValue("testaliastext", "text for alias"); //this field is set as the node alias source in type form definition
/////////////////////

// Insert the document into the content tree
newNode.Insert(parentNode);
}


}


And the node alias in CMS_Tree table is filled with the value from the testing column as it is set in Site Manager.

Best regards,
Juraj Ondrus

User avatar
Certified Developer v6
Certified Developer v6
hoppe - 12/14/2012 9:12:57 AM
   
RE:Use API to get which column name to use for node alias path and document name
Hi Juraj,

It seems like the document name field is the source of my question. My document type has the 'document source name field' set to the field 'title'.

If I create a new document using the source code we shared earlier, and do not have newNode.DocumentName explicitly set, the name of the document becomes 'new document', when it instead should take the value of my title field. Do you agree?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 12/17/2012 1:29:56 AM
   
RE:Use API to get which column name to use for node alias path and document name
Hi,

Thank you for the clarification, I got it now. Regrettably, it is a bug. I am sorry for this inconvenience. The current workaround is to specify the DocumentName property as well.

Best regards,
Juraj Ondrus

User avatar
Certified Developer v6
Certified Developer v6
hoppe - 1/8/2013 8:31:07 AM
   
RE:Use API to get which column name to use for node alias path and document name
Okay thanks!