Accessing Custom Fields
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
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
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;
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"
);
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?
Hi Alex,
Here is the API reference that shows the namespace and method signature.
All the best,
Ivan Dimitrov
the Telerik team
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;
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
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!
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
I am sorting by the newest first.
Thanks,
Alex Lorenz
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?
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
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
Hi Andrei,
Does the issue still persist? I cannot get whether you resolve it or not.
Kind regards,
Ivan Dimitrov
the Telerik team
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
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
Ok Ivan.
Thanks. I will investigate.
Andrei