Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > How can I retrieve multiple choice field options using API View modes: 
User avatar
Member
Member
joeh42 - 10/19/2011 4:03:12 PM
   
How can I retrieve multiple choice field options using API
I have a custom multiple choice field in the user - settings table. It's name/value pairs are stored as options. How can I retrieve those using the API?

I.e.:
Value1;Name1
Value2;Name2

Thanks,
Joe Hoppe

User avatar
Member
Member
kentico_michal - 10/24/2011 4:50:20 AM
   
RE:How can I retrieve multiple choice field options using API
Hello,

Please take a look at following code snippet that shows how you can get name/value pairs stored as options:


DataClassInfo info = DataClassInfoProvider.GetDataClass("<class name>");
if (info != null)
{
CMS.FormEngine.FormInfo fi = new CMS.FormEngine.FormInfo(info.ClassFormDefinition);
CMS.FormEngine.FormFieldInfo ffi = fi.GetFormField("<field name>");
string a = ValidationHelper.GetString(ffi.Settings["options"], "");

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml("<xml>" + Convert.ToString(ffi.Settings["options"]) + "</xml>");

System.Xml.XmlNode xmlNode = xmlDoc.FirstChild;

if (xmlNode.HasChildNodes)
{
foreach (System.Xml.XmlNode itemNode in xmlNode.ChildNodes)
{
string text = CMSContext.CurrentResolver.ResolveMacros(XmlHelper.GetAttributeValue(itemNode, "text"));
string value = CMSContext.CurrentResolver.ResolveMacros(XmlHelper.GetAttributeValue(itemNode, "value"));
}
}
}



Best regards,
Michal Legen