email parsing automation

Email Parser

Extract data from emails and automate your workflow

The forum is now read only. Please, go to the the main Email Parser website if you need help.
Post here if you experience problems or get unexpected errors.
I am trying to use script with switch/case statement.

This is the code:

[syntax="csharp"]
if(fields["FORWR"].Equals("1"))
{
Print("Forwarding to Responsible Party...");
Print("Case is " + fields["FORMD"]) ;
string ForwdCaseRP = fields["FORMD"] ;
Print("Case is " + ForwdCaseRP) ;
switch (ForwdCaseRP)
{
case "A":
CallAction("RepPartyFwdRegister",email, fields);
break ;
case "B":
Print("Forwarding Locate Distributor to " + fields["DFTTO"]) ;
CallAction("RepPartyFwdLocateDist",email, fields);
break ;
default:
Print("Using default forward method...") ;
break;
}
}
[/syntax]


When I run the script from the Test this automated process and populate the necessary fields, everything works as expected. However, when I run on "live" emails, the Case is never reached, it always runs the default. Can switch/case statement not be used?

Okay, I resolved this issue. It had to do with the actual field. But it brings up a question.... What was happening is that FORMD is defined as an 8 character field in the database. I load the field from the database and try to manipulate it. When I do, what is happening is that there is 1 trailing blank added to the field. So instead of looking for case "B", it needed to look for Case "B " (single space after).

What I did was add the Trim function to the switch...

switch (fields["FORMD"].Trim())

everything works fine now.

Now, question is, why does the parser add the trailing blank? If the field is defined as 8 characters, shouldn't there be 7 blanks after the "B"? ("B_______" instead of "B_")... (added the underscore for emphasis; when posting, it truncated all the blanks).
If the field value has a trailing space I think that it is probably because it indeed has a trailing space in the database. Could you send me your SQL sentence to test it here? It may also be a problem from Emaill&Parser.
Here is how the data base is created:

[syntax="sql"]
CREATE TABLE TEMLPARMS(
TFORMD FOR COLUMN FORMD CHAR(8) NOT NULL WITH DEFAULT ' ',
TFORMT FOR COLUMN FORMT CHAR(32) NOT NULL WITH DEFAULT ' ',
TDFTTO FOR COLUMN DFTTO CHAR(64) NOT NULL WITH DEFAULT ' ',
TDFTCC FOR COLUMN DFTCC CHAR(64) NOT NULL WITH DEFAULT ' ',
TDFTBC FOR COLUMN DFTBC CHAR(64) NOT NULL WITH DEFAULT ' ',
TNXTID FOR COLUMN NXTID DEC(9,0) NOT NULL WITH DEFAULT 0 ,
TPCNTR FOR COLUMN PCNTR DEC(9,0) NOT NULL WITH DEFAULT 0,
THCNTR FOR COLUMN HCNTR DEC(9,0) NOT NULL WITH DEFAULT 0,
TFORME FOR COLUMN FORME CHAR(32) NOT NULL WITH DEFAULT ' ',
TFLDLD FOR COLUMN FLDLD CHAR(1) NOT NULL WITH DEFAULT ' ',
TUSRAK FOR COLUMN USRAK CHAR(1) NOT NULL WITH DEFAULT ' ',
TFORWR FOR COLUMN FORWR CHAR(1) NOT NULL WITH DEFAULT ' ',
TFARCH FOR COLUMN FARCH CHAR(1) NOT NULL WITH DEFAULT ' ',
TXALOG FOR COLUMN XALOG CHAR(1) NOT NULL WITH DEFAULT ' ',
TTBLUP FOR COLUMN TBLUP CHAR(1) NOT NULL WITH DEFAULT ' ',
TEMLDL FOR COLUMN EMLDL CHAR(1) NOT NULL WITH DEFAULT ' ',
TOK2PR FOR COLUMN OK2PR CHAR(1) NOT NULL WITH DEFAULT ' ',
TTBLNM FOR COLUMN TBLNM CHAR(10) NOT NULL WITH DEFAULT ' ')
[/syntax]

This table is created on iSeries, and we are using the ODBC connector to access the file.


I set up a process to select the required fields:
[syntax="sql"]
select
FORMD, OK2PR, XALOG
from temlparms
where tformt = upper('<%form%>')
[/syntax]

'<%form%>' is a defined field on the email parser section; it comes from all our forms.

This is the entire section on how I ended up created the process to send required email (user acknowledgements):

[syntax="csharp"]
// This is a template for a script action.
// Check out:
// http://www.AutomatedEmailParser.com/doc ... o=topic304
// for further information and examples

using System;
using System.Text;
using System.IO;
using System.Net.Mail;
using System.Collections.Specialized;
using EmailAndParser.ScriptingInterface;

public class MyAction : ScriptBasedAction
{
public override bool Run(MailMessage email, NameValueCollection fields)
{
Print("Sending User Acknowledgement for " + fields["form"] + " to " + fields["email"]) ;
switch (fields["FORMD"].Trim())
{
// Registration
case "A":
CallAction("UserAckFormA",email, fields);
break ;

// Locate Distributor
case "B":
CallAction("UserAckFormB",email, fields);
break ;

// Dr Brake
case "C":
CallAction("UserAckFormC",email, fields);
break ;

// Sendmelit
case "D":
CallAction("UserAckFormD",email, fields);
break ;

case "E":
CallAction("UserAckFormE",email, fields);
break ;

case "F":
CallAction("UserAckFormF",email, fields);
break ;

case "G":
CallAction("UserAckFormG",email, fields);
break ;

case "H":
CallAction("UserAckFormH",email, fields);
break ;

case "I":
CallAction("UserAckFormI",email, fields);
break ;

case "J":
CallAction("UserAckFormJ",email, fields);
break ;

case "K":
CallAction("UserAckFormK",email, fields);
break ;

case "L":
CallAction("UserAckFormL",email, fields);
break ;

case "M":
CallAction("UserAckFormM",email, fields);
break ;

case "N":
CallAction("UserAckFromN",email, fields);
break ;

case "O":
CallAction("UserAckFormO",email, fields);
break ;

default:
Print("Using default forward method...") ;
break;
}
// this action finishes successfully
return(true);
}
}
[/syntax]

I actually have this working very well now. What we are trying to do is have all our forms emails that are created from our web site send the appropriate response back to the user based on the type of form that it is, and upload the details of each email to our iSeries. Not as many people know about the iSeries as other platforms; I had searched for quite some time to find a product to allow what we are doing which was relatively inexpensive. There are lots of solutions out there, but many want thousands of dollars when you mention the word iSeries. Your product has been one of the best investments we have ever made... I have a lot of people upset with me now because we are logging and tracking every single piece of email that comes to our organization and employees actually have to do their job instead of saying "I never received that email".
I have tested the SQL sentence here and it seems to return the field value without the trailing space. To be frank I do not know why it is giving you that space.
Your product has been one of the best investments we have ever made... I have a lot of people upset with me now because we are logging and tracking every single piece of email that comes to our organization and employees actually have to do their job instead of saying "I never received that email".
:) It is always nice to know details about the actual scenario of use. Thanks for the good feedback and posting it here