Home > DynamicsAx Utilities > Dynamics Ax Document Handling For The Mails Using Drag n Drop

Dynamics Ax Document Handling For The Mails Using Drag n Drop


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

Rainbow……..Smile

Advertisements
Categories: DynamicsAx Utilities
  1. Thomas
    November 20, 2009 at 3:08 pm

    HiDo you know how to handle just the drag and drop of an attachment from Outlook to AX?Thomas

  2. Santosh Kumar
    November 24, 2009 at 6:46 am

    HiBy this example, mails (mail items) will be refered for document handling along with the attachments also…if you need explicitly for attachments only, let me try wtih that example and i will update you accordingly.Regards,Santosh Paruvella

  3. Mallikarjun
    November 25, 2009 at 4:45 am

    WOW!!! Santosh sir, eam sir full chipesthunnaru… very good. so Vela lo out look project inkka paniki vosthundhi.. hahahaha any way.. congratulations wonder full work.

  4. Santosh Kumar
    November 25, 2009 at 5:43 pm

    Thank you very much mallik… :-)As you said we are very much thank full to Vela Software, there we got a chance to start our careers in Dynamics Ax(Axapta) platform.I want to say my Heart full thanks to my PM in Vela software, Mr. Srinivas Titti. 🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: