Use BeforeDocumentImport to access the current attachment
You can use the BeforeDocumentImport function to access the current attachment using a script.
public void BeforeDocumentImport(IDictionary<string, string> indexFields,
IDictionary<string, string> folderFields,
IDictionary<string, string> batchFields,
List<Attachment> messageBody,
List<Attachment> attachments,
object extension)
There are two lists which are accessible in the script: "messageBody" and "attachments". The "object extension" parameter is enhanced to store information about the current attachment. This allows you to select the relevant attachment from the parameter "messageBody" or "attachments".
Parameter |
Description |
---|---|
CurrentMsgInfo.currentImport |
Stores the information about attachment type: Body type or attachment type. |
CurrentMsgInfo.currentAttachment |
Stores the index of current attachment in the list. |
CurrentMsgInfo.currentPageList |
Stores the index of all the pages in the attachment list. Use the "currentPageList" property only when the destination is configured for "XMLImport Connector compatible" or "Generic" XML mapping. In all other cases, use the "currentAttachment" property. |
Procedure to know the current attachment:
-
Check if the current attachment is in the "attachments" list of "messageBody" list.
Use the "extension" object:
Dictionary<string, object> arguments = (Dictionary<string, object>)extension; CurrentMsgInfo info = (CurrentMsgInfo)arguments["CurrentMsgInfo"]; Attachment currAtt = null; if (info.currentImport == ImportData.ATTACHMENT) //current Attachment is in attachments list else if (info.currentImport == ImportData.MESSAGE_BODY) //current Attachment is in messageBody list else if (info.currentImport == ImportData.PAGE_LIST) //current document has list of pages (attachments)
Note the following:
-
CurrentMsgInfo info.currentImport will always return ImportData.MESSAGE, if all of the following conditions are true:
- "Create document per attachment" is not selected, and
- XML mapping is not configured for "XMLImport Connector compatible" or "Generic xml"
-
When XML mapping in the destination is configured for "XMLImport Connector compatible" or "Generic xml":
- Documents are created as per the XML data and it does not depend on "Create document per attachment" option.
- currentImport property of CurrentMsgInfo will return ImportData.PAGE_LIST.
-
-
Find the index of the current attachment in the list.
-
Info.currentAttachment holds the index of current attachment.
-
If Info.currentAttachment is less than 0, the current Import is of type message.
-
If info.currentPagelist is not null, current document has list of pages (attachments.)
-
-
Access the current attachment using list and current index.
if (info.currentImport == ImportData.ATTACHMENT) currAtt = attachments[info.currentAttachment]; else if (info.currentImport == ImportData.MESSAGE_BODY) currAtt = messageBody[info.currentAttachment]; else if (info.currentImport == ImportData.PAGE_LIST) { currPageList = new List<Attachment>(); for (int i = 0; i < info.currentPageList.Count; i++) currPageList.Add(attachments[info.currentPageList[i]]); }
Sample code that can be used in script file's BeforeDocumentImport() function:
public void BeforeDocumentImport(IDictionary<string, string> indexFields, IDictionary<string, string> folderFields, IDictionary<string, string> batchFields, List<Attachment> messageBody, List<Attachment> attachments, object extension)
{
Dictionary<string, object> arguments = (Dictionary<string, object>)extension;
CurrentMsgInfo info = (CurrentMsgInfo)arguments["CurrentMsgInfo"];
Attachment currAtt = null;
if (info.currentImport == ImportData.ATTACHMENT)
currAtt = attachments[info.currentAttachment];
else if (info.currentImport == ImportData.MESSAGE_BODY)
currAtt = messageBody[info.currentAttachment];
else if (info.currentImport == ImportData.PAGE_LIST)
{
currPageList = new List<Attachment>();
for (int i = 0; i < info.currentPageList.Count; i++)
currPageList.Add(attachments[info.currentPageList[i]]);
}
}
Class added in API:
public class ImportData
{
public const string MESSAGE="MESSAGE";
public const string MESSAGE_BODY="MESSAGE BODY";
public const string ATTACHMENT="ATTACHMENT";
}
public class CurrentMsgInfo
{
public string currentImport = "";
public int currentAttachment = -1;
public List<int> currentPageList=null;
}
Identification of Message Type based on CurrentImport and CurrentAttachment
"Create document per attachment" UI Option |
CurrentImport |
Message type |
CurrentAttachment |
---|---|---|---|
Clear |
|
Entire message |
-1 |
Selected |
|
Body |
currentAttachment >=0 Attachment currAtt = messageBody[info.currentAttachment]; |
|
Attachment |
currentAttachment >=0 Attachment currAtt = attachments[info.currentAttachment]; |
|
Not applicable |
|
Page list |
-1 Current page list can be accessed using following code:
|