I'm trying to map multiple address fields from my source (i.e. address 1, City, State, Zip) into a target field which is a multi-line textbox.
I'm using the OOTB "Collection to String Value" reader as the Source Value Transformer within the address mapping.
However, it appears my delimiter of \r\n is being encoded somehow, so instead of line breaks i get
Address1\r\n\City\r\nState\r\nZip
Any way I can map multiple fields into separate lines in a multi-line textbox?
I probably need to write my own reader to transform the value - but I wanted to check if there was a better way first.
I'm also going through the framework code - and i don't see where the value is actually encoded - so i'm concerned if i DO write a custom value reader my value will just end up encoded as well - so i think i need to find that FIRST so i know how to avoid it
For example, The ootb value reader is only this
public virtual ReadResult Read(object source, DataAccessContext context)
{
if (source == null)
return ReadResult.PositiveResult((object) null, DateTime.Now);
ICollection collection = source as ICollection;
if (collection == null)
return ReadResult.NegativeResult(DateTime.Now);
List<object> objectList = new List<object>();
foreach (object obj in (IEnumerable) collection)
objectList.Add(obj);
return ReadResult.PositiveResult((object) string.Join<object>(this.Separator, (IEnumerable<object>) objectList), DateTime.Now);
}
So it seems that simply writing my own value reader to add line breaks is pointless as unless I figure out how to avoid the encoding.
UPDATE -Solution from Vlad below was it. Below is the updated converter in case it helps others.
protected override ConvertResult<IValueReader> ConvertSupportedItem(ItemModel source)
{
return this.PositiveResult((IValueReader)new CollectionToStringValueReader()
{
Separator = PreserveLineBreaks(this.GetStringValue(source, FieldNameSeparator))
});
}
private string PreserveLineBreaks(string separator)
{
var unescapedSeparator = Regex.Unescape(separator);
return unescapedSeparator == Environment.NewLine ? unescapedSeparator : separator;
}
\r\n
as a break line. You might need to change the field type to Rich Text or add a custom Multi-Line Text field