API Questions on Kentico API.
Version 6.x > API > Getting custom field View modes: 
User avatar
Member
Member
vasiliy.ivanov1975-gmail - 11/9/2012 1:17:16 AM
   
Getting custom field
Hello,
In the site I'm working with, while editing some page in CMS Desk, I have several custom data fields on the From tab (from the bar where are "Page", "Design", "Form", "Properties", "Analytics"). Those data fields were made by the site developers according to our company regards and are not common for Kentico.

Those fields' names are presented in CMSContent.CurrentDocument.ColumnNames[], but trying retrieve their values using CMSContent.CurrentDocument.GetValue("someFieldName") I get 'null'. What am I doing wrong?

Thank you in advance.

User avatar
Kentico Support
Kentico Support
kentico_radekm - 11/20/2012 5:55:15 AM
   
RE:Getting custom field
Hello.

Were these custom fields added into form definition of the given document in a standard way, in the Site Manager / Development / Document types / edit / Fields tab?

If you call macro below in some web part's property placed on that page, does it return required value?
{%CurrentDocument["<column code name>"]%}

Where exactly you call that CMSContent.CurrentDocument.GetValue("someFieldName") code? As this is not a macro expression but direct C# code, I guess you call it somewhere in the code-behind?

When you debug it, it "CurrentDocument" object not null and are you sure that codeName in GetValue() method is correct? Thank you.

Best Regards,
Radek Macalik

User avatar
Member
Member
vasiliy.ivanov1975-gmail - 11/23/2012 8:56:01 AM
   
RE:Getting custom field
Sorry for late answer.
Not "CMSContent", but "CMSContext", my mistake.

I call CMSContext.CurrentDocument.GetValue("someFieldName") in code-behind, and "CurrentDocument" object exists.

But - when I tried to substitute the column name in lowercase - it worked and returned appropriate result. For example, CMSContext.CurrentDocument.GetValue("documenturlpath") returns correct string. Although in CMSContext.CurrentDocument.ColumnNames list it figures as "DocumentUrlPath".

User avatar
Kentico Support
Kentico Support
kentico_radekm - 12/7/2012 4:03:04 PM
   
RE:Getting custom field
Hello.

Method always converts it to lowercase internally, so it should not matter whether you type it in lowercase or not. Are you still unable to retrieve values of the document type’s field using this approach?

Were these custom fields added into form definition of the given document in a standard way, in the Site Manager / Development / Document types / edit / Fields tab?

Thank you.

Best Regards,
Radek Macalik

User avatar
Member
Member
vasiliy.ivanov1975-gmail - 12/10/2012 5:26:52 AM
   
RE:Getting custom field
Hello.

Yes, the custom fields were added in a standard way. Using names in lowercase, I got values contained in the fields.

But than I refused using custom fields, and just placed CMSEditableRegion to the page.