This area of the website is no longer being updated.
Changes and news are now published on this page.

How to merge multiple field values into one

February 26, 2019
Email Parser processes the emails running items (Email sources, Parsers and Actions) one after another, in a sequential way. In each step, a set of fields are created based on the results of the previous steps. For instance, an Email Source creates the field Subject and then a Parser can use this field to capture, let’s say, an invoice number. There are fields, like the To, CC and BCC that can contain multiple values. For example, the following email contains two values in the CC field:
Multiple field values is something that also happens as a result of parsing, for instance, the body of an email:
Having the values separated, like in an spreadsheet, is what makes most sense in the majority of the cases. But it could happen that you need them merged into a single text value. In order to get this you have to run a small script like the following:
using System;
using System.Text;
using System.IO;
using System.Net.Mail;
using System.Collections.Specialized;
using EmailParserBackendApi.ScriptingInterface;

public class MyAction : ScriptBasedAction
{
    // Implement this method with your own code. Run() will be called each time
    // this Action runs
    public override bool Run(MailMessage email, NameValueCollection fields)
    {
    	string output="";
	foreach(string value in fields.GetValues("CC_cleaned"))
		output+=value+",\r\n";

	fields.Add("Merged_CC_values", output.Trim(new char[]{',','\n','\r'}));
        
        return (true);
    }
}

This script was written in reply to this question at the forum. In the following screenshots you can see step-by-step how it is used. But, basically, we do the following:
  1. Taking the email addresses in the CC field, discarding the name. For example, if the CC field is “John Doe” <john@example.com> we take only john@example.com. We do this in the Parser, under the field “CC_cleaned”
  2. Running the script to merge the resulting email addresses into one comma separated value

© 2008-2024 Triple Click Software
News & Updates

Privacy Policy & Terms of Use
PAD fileยทOld news