Developer forum

Forum » Development » CustomFields on News

CustomFields on News


Reply

I have a NewsItem object and I want to get all it's customfields, how do I do that?

I have this exsample code:

foreach(NewsItem ni in GetNewsListFromCategory("9", Dynamicweb.NewsV2.NewsItem.NewsStatus.All, Dynamicweb.NewsV2.NewsItem.SortFields.NewsDate, Dynamicweb.Modules.Common.Lists.SortDirection.ASC, "", 0, 999, false))
            {

                //And now I what to get all the customfields on the current "ni" object. Any idea how, please fill in :)
            }

 


Replies

 
Reply
Hi Kim,
 
To retrieve a list of all general custom fields please use the following construct:
 
Dynamicweb.Modules.Common.CustomFieldCollection fields = Dynamicweb.Modules.Common.CustomField.GetListWithValues(Dynamicweb.NewsV2.Consts.GeneralCustomFieldContext, ni.ID);
 
Also there might be some group-specific custom fields. A list of these fields can be retrieved using the following code example:
 
Dynamicweb.Modules.Common.CustomFieldCollection fields = null;
Dynamicweb.NewsV2.NewsCategory cat = new Dynamicweb.NewsV2.NewsCategory(ni.NewsCategoryID);

cat.LoadGroups();

if(cat.Groups.Count > 0)
fields = Dynamicweb.NewsV2.CustomFieldSpecific.GetListWithValues(ni.ID, cat.Groups[0].ID);

Hope this will help you.

Pavel.

 
Reply
Works great. Nice article :)

 

You must be logged in to post in the forum