Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Use API to get CMS Site Manager default values for document type fields? View modes: 
User avatar
Certified Developer v6
Certified Developer v6
hoppe - 12/5/2012 9:11:55 AM
   
Use API to get CMS Site Manager default values for document type fields?
I have a custom document type called health article.

When I use the API to create a new document, it does not honor the default values for the fields that I have set in the CMS Site Manager. I.e., I have a field IncludeInWeeklyAlert with the default setting to true. When I create a new node of this type, I receive an error that the field cannot be null.
var tree = new TreeProvider(UserInfoProvider.GetUserInfo("administrator"));

using (var parentNode = tree.SelectSingleNode(CMSContext.CurrentSiteName, parentNodePath, "##ALL##", true, "CMS.MenuItem", false))
{
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);

// Set the document's properties
// Insert the document into the content tree
newNode.Insert(parentNode);

How can I use the API to get the default value, so that I do not have to put the default value in more than 1 place?

Thanks,
Joe Hoppe

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 12/7/2012 1:36:03 AM
   
RE:Use API to get CMS Site Manager default values for document type fields?
Hi,

When using the API, you need to set all the required fields. I think, it is much easier to just set that field for the document while creating - it is less operations than getting the document type definition, parsing the default value and then setting it anyway for the document.

Best regards,
Juraj Ondrus

User avatar
Certified Developer v6
Certified Developer v6
hoppe - 12/10/2012 11:58:18 AM
   
RE:Use API to get CMS Site Manager default values for document type fields?
Hi Juraj,

I will request that this be made more easily available through user voice.

Thanks!

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 12/13/2012 3:14:45 AM
   
RE:Use API to get CMS Site Manager default values for document type fields?
Hi,

As I can see in the user voice - I was wrong. I was not aware of that API method. I am posting it here as well for others reference.

You can use code like this:

// Create new document instance
var tree = new TreeProvider(CMSContext.CurrentUser);
var className = "cms.news";
var node = TreeNode.New(className, tree);

// Load default data
FormHelper.LoadDefaultValues(className, node);


Best regards,
Juraj Ondrus


User avatar
Certified Developer v6
Certified Developer v6
hoppe - 12/13/2012 11:44:04 AM
   
RE:Use API to get CMS Site Manager default values for document type fields?
Thanks!