Accessing Custom Fields

Posted by Community Admin on 03-Aug-2018 15:24

Accessing Custom Fields

All Replies

Posted by Community Admin on 20-Jan-2011 00:00

I have added custom fields to the news content, but when I am not able to access those properties through the NewsManager.  Is there a different process to access the custom fields?

Thanks,
Alex Lorenz

Posted by Community Admin on 20-Jan-2011 00:00

Hi Alex,

There are methods SetValue and GetValue of Telerik.Sitefinity.Model.DataExtensions that you can use to get/set metafields

Greetings,
Ivan Dimitrov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 20-Jan-2011 00:00

When I loop through the news items do I call the GetValue method then or do I have to do it a different way.  Here is how my code looks:

NewsManager manager = NewsManager.GetManager();
IQueryable<NewsItem> newsItems = manager.GetNewsItems()
                  .Where(t => t.Status == ContentLifecycleStatus.Live)
                  .OrderByDescending(o => o.PublicationDate);
 
int i = 0;
 
foreach (NewsItem item in newsItems)
    i++;
                    
    this.items.InnerHtml += "<div id=\"" + item.Id + "\">" + item.Title + "</div>" + Environment.NewLine;
 
    if (i > 5)
    
        break;
    

Posted by Community Admin on 21-Jan-2011 00:00

Hello Alex,

Here is a sample code that you can use

var newsItems = App.WorkWith().NewsItems()
.Where(t => t.Status ==Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live)
.OrderByDescending(o => o.PublicationDate)
.Get()
.ToList();
 
            foreach (var item in newsItems)
            
                var summary = item.GetValue("Summary");
            


Kind regards,
Ivan Dimitrov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 21-Jan-2011 00:00

I'm getting the following error on the GetValue method: 

'Telerik.Sitefinity.News.Model.NewsItem' does not contain a definition for 'GetValue' and no extension method 'GetValue' accepting a first argument of type 'Telerik.Sitefinity.News.Model.NewsItem' could be found (are you missing a using directive or an assembly reference?)

I have tried adding a reference to Telerik.Sitefinity.Model.DataExtensions, but it says it does not exist.  What am I missing?


Posted by Community Admin on 21-Jan-2011 00:00

Hi Alex,

Here is the API reference that shows the namespace and method signature.

All the best,
Ivan Dimitrov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 21-Jan-2011 00:00

All the code seems to look correct now, but when I go to utilize the value it is blank even though it is not null.  Am I not utilizing the var correctly?

var HeadlineImage = item.GetValue("HeadlineImage");
                 
if (HeadlineImage.ToString().IsNullOrEmpty())
       this.items.InnerHtml += "<img src=\"" + HeadlineImage.ToString() + "\" />" + Environment.NewLine;

Posted by Community Admin on 21-Jan-2011 00:00

Hi Alex,

Most probably there is no value set for HeadlineImage for the item you use. Please make sure that you have set value for this item by using SetValue and you have called SaveChanged().

All the best,
Ivan Dimitrov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 21-Jan-2011 00:00

There were values set, but I was missing an if statement.  However, I noticed that if I update one news item that was initially 3rd when returned, it is now 1st.  Is there an "original" publish date so that if changes get made to an already published news item that it won't move up in order?

Thanks for all your help!

Posted by Community Admin on 26-Jan-2011 00:00

Hello Alex,

There are sorting settings for news list. Can you please check what are your sorting settings in the news view control?

Kind regards,
Radoslav Georgiev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 26-Jan-2011 00:00

I am sorting by the newest first.
Thanks,
Alex Lorenz

Posted by Community Admin on 06-Jul-2011 00:00

Hi,

I have the latest build 4.1.1501.0 and on my development machine with IE8, I can access the Custom Fields for news, but when I publish the application and take it on the test system with IE9, I cannot access the Custom Fields for news. It says that the default fields cannot be edited or hidden. also, it says that no custom fields have been added when I have one on the page added from a long time ago. The same version on my development PC shows everything as it always did but on the test machine it does not. Also, on the test machine it switched all the labels to the defaults. What happens between me publishing it on the development machine and running it on the test machine that all the resources switch to their defaults. Could the different version of IE do all that?

Posted by Community Admin on 07-Jul-2011 00:00

Hello Andrei,

This should not be a browse issue. It looks like the configuration files form App_Data are not moved or you are not using the correct database.

Best wishes,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 11-Jul-2011 00:00

Ivan,

I am deleting all the files and completely replace them with the newly published. Also, I back-up the database as well on which I am working upstairs and restore it downstairs. Not too sure what's going on.

Thanks,
Andrei

Posted by Community Admin on 11-Jul-2011 00:00

Hi Andrei,

Does the issue still persist? I cannot get whether you resolve it or not.

Kind regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 11-Jul-2011 00:00

Ivan,

It happens when I switch from my development PC to the test PC. But when I change the resource labels then it is ok. Not sure why that happens. It does not remember them accross, but remembers everything else.

Thanks,
Andrei

Posted by Community Admin on 12-Jul-2011 00:00

Hi Andrei,

From the description you are providing it looks like that not all data is moved between both the machines. You are missing some config file or some database entry ( if you use database replication tool).

Best wishes,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 12-Jul-2011 00:00

Ok Ivan.
Thanks. I will investigate.
Andrei

This thread is closed