Hi everybody,
I'm currently looking for a solution for Navision 4.03 to read the Outlook Inbox and to save the attachment to a specified location from where it will be extracted and converted by Navision (since my code to save attachment within Outlook is not functioning anymore after Outlook is closed and restarted).
I've been playing with the 'NS Outlook Synchronization Handler' - scanning the inbox is fairly easy but once I've selected an oInboxItem I cannot set the oAttachments to this item. ](*,)
I seems to me that the creators of this automation have been focussing on sending a mail only...
I hope somebody has the right solution to solve this problem.
Thanks in advance,
Frank
FH
0
Comments
RIS Plus, LLC
I did already solve this issue by accessing Outlook Automation directly ( :idea: ) , as long as Outlook remains backwards compatible it should work. Basically it is the same solution as your suggestion.
// Variables
Name DataType Subtype Length
autOLAppl Automation 'Microsoft Outlook 11.0 Object Library'.Application
autOLNamespace Automation 'Microsoft Outlook 11.0 Object Library'.NameSpace
autOLItems Automation 'Microsoft Outlook 11.0 Object Library'.Items
autOLMapiFolder Automation 'Microsoft Outlook 11.0 Object Library'.MAPIFolder
autOLMailItem Automation 'Microsoft Outlook 11.0 Object Library'.MailItem
oAttachments Automation 'Microsoft Outlook 11.0 Object Library'.Attachments
oAttachment Automation 'Microsoft Outlook 11.0 Object Library'.Attachment
txtFindCriteria Text 250
intEndOfLoop Integer
i Integer
z Integer
NoOfSavedFiles Integer
// Code
CLEAR(autOLAppl);
CREATE(autOLAppl);
autOLNamespace := autOLAppl.GetNamespace('MAPI');
autOLNamespace.Logon('','',TRUE,FALSE);
autOLMapiFolder := autOLNamespace.GetDefaultFolder(6);
autOLItems := autOLMapiFolder.Items;
txtFindCriteria := '[Sendername] = '<originator of mail>';
autOLItems := autOLMapiFolder.Items.Restrict(txtFindCriteria);
CLEAR(NoOfSavedFiles);
i := 1;
intEndOfLoop := autOLItems.Count;
IF intEndOfLoop > 0 THEN
Window.OPEN('Mail From #1############################################\' +
'Subject #2############################################\' +
'Attachments #3## #4#####################################');
WHILE i <= intEndOfLoop DO BEGIN
autOLMailItem := autOLItems.Item(i);
// Only Process if UnRead yet
IF (autOLMailItem.UnRead = TRUE) THEN BEGIN
oAttachments := autOLMailItem.Attachments;
Window.UPDATE(1, autOLMailItem.SenderName);
Window.UPDATE(2, autOLMailItem.Subject);
Window.UPDATE(3, FORMAT(oAttachments.Count) );
IF oAttachments.Count <> 0 THEN BEGIN
// Run Though Attachments
FOR z := 1 TO oAttachments.Count DO BEGIN
oAttachment := oAttachments.Item(z);
Window.UPDATE(4, oAttachment.FileName);
oAttachment.SaveAsFile('<save 2 location>', oAttachment.FileName);
NoOfSavedFiles += 1;
END;
END;
// Mark As READ (By Navision)
autOLMailItem.UnRead(FALSE);
autOLMailItem.Close(1);
END;
i := i + 1;
END;
CLEAR(autOLMailItem);
CLEAR(autOLAppl);
You can basically use the VBA code as a template for C/AL code, you just have to make sure you handle type conversion, and events are difficult to use. Browse the automation subtypes, you'll be surprised at how much is available there.
RIS Plus, LLC