Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Transformation method for one-to-many, pipe-delimited methods. View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
dchaffin-hgo - 11/18/2013 9:06:09 AM
   
Transformation method for one-to-many, pipe-delimited methods.
I looked for a while on how to transform pipe-delimited values from a field list-box and couldn't find anything specific - only general information about how to write a transformation method. So, I did that and tried to make it pretty generic and thought I'd share what I came up with. If anyone has any suggestions for improvement, they would be greatly appreciated.

public static string Lookup(object _value, string _classNames, string _valueField, string _textField)
{
NodeSelectionParameters _params = new NodeSelectionParameters();
_params.SelectOnlyPublished = true;
_params.SiteName = CMS.CMSHelper.CMSContext.CurrentSiteName;
_params.ClassNames = _classNames;
_params.Where = _valueField + " IN (" + _value.ToString().Replace('|',',') + ")";
_params.OrderBy = _valueField;

TreeProvider _tree = new TreeProvider();

var _dataSet = _tree.SelectNodes(_params);
if (_dataSet != null)
{
StringWriter stringWriter = new StringWriter();
using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
{
var _nodes = _dataSet.Items;
if(_nodes.Count == 1){
writer.Write(ValidationHelper.GetString(_nodes[0][_textField], String.Empty));
} else {
writer.RenderBeginTag(HtmlTextWriterTag.Ul);
foreach (CMS.DocumentEngine.TreeNode _node in _nodes)
{
writer.RenderBeginTag(HtmlTextWriterTag.Li);
writer.Write(ValidationHelper.GetString(_node[_textField], String.Empty));
writer.RenderEndTag();
}
writer.RenderEndTag();
}
}
return stringWriter.ToString();
}

return "";
}

User avatar
Certified Developer v7
Certified  Developer v7
dchaffin-hgo - 11/18/2013 9:17:02 AM
   
RE:Transformation method for one-to-many, pipe-delimited methods.
Of course, as soon as I post that, I experience an error with it if an empty value is passed in. Adding this to the top solved it ...

if(_value.ToString().Trim() == String.Empty){ return ""; }

User avatar
Certified Developer 12
Certified Developer 12
chetan2309-gmail - 11/18/2013 6:44:57 PM
   
RE:Transformation method for one-to-many, pipe-delimited methods.
Hi dchaffin-hgo,

You can use LIKE query. I have used it at so many places. It should solve your purpose.

Thanks,
Chetan

User avatar
Certified Developer v7
Certified  Developer v7
dchaffin-hgo - 11/18/2013 7:24:04 PM
   
RE:Transformation method for one-to-many, pipe-delimited methods.
Thanks for the reply! However, I'm not sure what you mean. How will a LIKE query help me turn something that looks like this ...

1|4|13

... into a more meaningful ...

Doc Title 1
Doc Title 2
Doc Title 3

User avatar
Member
Member
kentico_sandroj - 12/1/2013 1:11:46 PM
   
RE:Transformation method for one-to-many, pipe-delimited methods.
Hello,

Your approach for replacing the pipes is fine. Other optios are to create a custom function for transformation in which code you will parse the value and replace pipe (|) with the comma as you need to.

Second option is creating fully custom form control which will sort the values in desired format and then use this form control as a field for your document type.

Best Regards,
Sandro