Skip to main content

Reject message based on content of Email Subject using KIC scripting


QAID # 19400 Published

Question / Problem:

How can I reject a message based on the content of an Email Subject using KIC scripting?

Answer / Solution:

The KIC 2 Developers Guide describes, on page 41, that you have to throw an exception if you want to reject a message.

It states:

Rejecting Messages from Script
You can perform checks and reject messages with scripts that implement the IDocumentScript2 interface. To reject a message, throw an exception of the type ScriptException with the desired description as an argument. The description is then displayed in Message Connector Monitor.

If you want to check, for example, that the message subject contains "INVOICE", you can use the following method (this code is provided as is):

(The GetFieldValue helper function is the same as already used in the "SampleDocumentScript.cs")

public void BeforeMessageImport(IDictionary<string, string> indexFields,
IDictionary<string, string> folderFields,
IDictionary<string, string> batchFields,
List<Attachment> messageBody,
List<Attachment> attachments,
object extension)
string strSubject = GetFieldValue("KfxMessageSubject", batchFields);
if (strSubject.ToLower().Contains("factura"))
throw new ScriptException("Message subject is not correct");

This is assuming that the Batch Class where the message is imported contains a KfxMessageSubject Batch Field (as it is for the delivered Sample Batch Classes).

Applies to:

Product Version
KIC 2.0