Developer forum

Forum » Development » Get label for category field value

Get label for category field value

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars

Hi there,

I have an integration that sends Dynamicweb product data to another system. As part of the integration, I need to send it the friendly labels for category fields of type List box (e.g. Radiobutton list). I currently have something like this:

var type = p.GetCategoryValue("CategoryName", "CategoryFieldName")?.ToString() ?? "";

This gives me the value of the field in the list box (i.e. something like Cat1) but I am looking for the friendly name (something like "Category 1"). How do I go about that? 




Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
This post has been marked as an answer

Hi Imar,

Instead of just getting the value, you can get the field as well. Then you can get the value as usual and get the option from the field. Given the option, you can get its name. Something like this:

var field = Dynamicweb.Ecommerce.Services.ProductCategoryFields.GetFieldById("CategoryName", "CategoryFieldName")
var value = p.GetCategoryValue(field.CategoryId, field.Id);
var optionLabel = field.Options.Find(o => o.Value == value).GetName("LanguageId");

I hope that helps.

- Jeppe

Votes for this answer: 1


You must be logged in to post in the forum