|
20.11.2009, 20:05 | #1 |
Участник
|
paruvella: Dynamics Ax Document Handling For The Mails Using Drag n Drop
Источник: http://paruvella.spaces.live.com/Blo...4DB0!324.entry
============== In my previous article, I had placed the example of Dynamics Ax Document handling for the files using Drag ‘N’ Drop option. In this article, we are going to see the example of Document handling for the mails (Outlook –Mail Items) using Drag ‘N’ Drop option. Steps: 1) Create a new form in Dynamics Ax and name it as MailDragnDrop_Paruvella. 2) Go to AOTàFormsà MailDragnDrop_ParuvellaàDesigns àDesign, right click and select the New control and from the control list select ActiveX control 3) Ax will open the list of ActiveX controls box (ActiveX Browser) and select the smmDrop2.smmDropWin class from available controls list 4) Add a new method for the ActiveX control as follows void onEvent_DropMail(COMVariant bMailIn, COMVariant strEntryID, COMVariant strStoreID) { DocuRef docuRef; ; //Here I am passing CustAccountNum as 113443 i.e. I am attaching the mail item to this customer docuRef.RefRecId = CustTable::find("113443").RecId; docuRef.RefTableId = tablenum(CustTable); if (MailDragnDrop_Paruvella::docuHandleDroppedEMail(docuRef, strEntryID.bStr(), strStoreID.bStr())) { info("Document attached successfully"); } else { info("not attached"); } } 5) Now create a new class and name it as MailDragnDrop_Paruvella 6) Add a new method to the class as follows public client static boolean docuHandleDroppedEMail(DocuRef _docuRef, smmEMailEntryID smmEMailEntryID = '', str smmEMailStoreID = '') { #define.outlookapplication('Outlook.Application') #define.mapidef('MAPI') #define.msgfile('msg') NumberSeq numSeq; str tofilename; COM outlook; COM namespace; COM item; FilePath archivePath; DocuRef docuRef = _docuRef; int lines = infolog.line(); InteropPermission permission; DocuActionArchive docuActionArchive; str mailSubject, fileName, fileType; ; permission = new InteropPermission(InteropKind::ComInterop); permission.assert(); // Initialize communication with Outlook outlook = new COM(#outlookapplication); if (outlook) { // Get Outlook namespace namespace = outlook.getNamespace(#mapidef); if (namespace) { // Get Outlook mail item item = namespace.getItemFromId(smmEMailEntryID, smmEMailStoreID); } } // Check that the Outlook mail item was found if (!item) { return checkFailed("Outlook communication error. The mail item not found"); } archivePath = Docu::archivePath(curExt()); if (! archivePath) { // The Windows path is used because the Outlook mail must be written somewhere on disk as a temp file before it can be saved in the database archivePath = WinAPI::getWindowsDirectory(); } // Get a new number from the document numbersequence numSeq = NumberSeq::newGetNum(DocuParameters::numRefDocuNumber(), true); // Use next number in numbersequence as filename fileName = smmDocuments::getNonExistingFileName(numSeq, archivePath, #msgfile); // Save mail as the msg type file fileType = #msgfile; // If path doesn't end with to backslash it should be appended archivePath = Docu::fileCheckPath(archivePath); //docuValue.Path = archivePath; // Create filename based on the path in the document type table and the filename (number) tofilename = archivePath + fileName + (fileType ? ('.' + fileType) : ''); // Save the e-mail as a .msg file try { // Call save function on the Outlook mail item item.saveAs(tofilename); mailSubject = item.subject(); } catch { // If the save function displays a COM error it should not be shown in the infolog infolog.clear(lines); } // Check that the file was saved correctly if (!archivePath || !WinAPI::fileExists(tofilename)) { // Free the document numbersequence number that was reserved if the file wasn't found numSeq.abort(); return checkFailed("The file could not be saved"); } CodeAccessPermission::revertAssert(); ttsbegin; // Mark the document numbersequence number is used numSeq.used(); // Create the document docuRef.Name = mailSubject; docuRef.TypeId = "Fil"; // this value is File here. docuRef.Notes = ""; docuRef.RefCompanyId = curExt(); docuRef.Restriction = DocuRestriction::Internal; docuRef.InterCompanySkipUpdate = InterCompanySkipUpdate::No; docuRef.smmTable = boolean::true; docuRef.ActualCompanyId = curExt(); docuRef.PartyId = "2"; docuRef.ContactPersonId = ""; docuRef.DEL_BusRelAccount = ""; docuRef.AuthorId = "100"; //curUserid -- employee Id docuRef.smmEMailEntryID = smmEMailEntryID; docuRef.smmEMailStoreID = smmEMailStoreID; docuRef.DEL_CampaignId = ""; docuRef.EncyclopediaItemId = ""; docuRef.insert(); ttscommit; ttsbegin; docuRef.selectForUpdate(true); docuActionArchive = new DocuActionArchive(); docuActionArchive.add(docuRef, tofilename); ttscommit; return true; } 7) Save and Compile the Class and Form. 8) Run the form and open the mail box (make sure that two windows are visible by resizing the mail box) 9) Select the mail from mailbox drag the mail and drop on to the ActiveX component of the form as show in below figure. 10) After this drag n drop option is completed, we will be prompted with following prompt 11) Just click on Allow button of the message box (it may appear 2-3 times click on Allow button always) 12) Then the selected mail will be attached to the customer record as a Outlook Message Item (*.msg). Find the complete project for this example at the following location. http://cid-f2ec589e221a4db0.skydrive.live.com/self.aspx/.Public/DynamicsAx%20Utilities/DocHandlingForMailItems/SharedProject%5E_MailDragNDropDocHandling%5E_Paruvella.xpo ........ Источник: http://paruvella.spaces.live.com/Blo...4DB0!324.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
|