September 27, 2012

How to Restore deleted sales order or purchase order

How to Restore deleted sales order or purchase order in AX 2009






Hi Frnds,

Some times fortunately or unfortunately user delete a record from Purchase Order OR Sales Order Forms,
and it can be drag you in a big problems, Here I am sharing a trick to restore these deleted Order records.
When ever a record is deleted from a Form, it sits in the void tables. These orders can be viewed from

AR -> Inquiries -> History -> Voided sales order or AP -> Inquiries -> History -> Voided Sales order.

AP -> Inquiries -> History -> Voided sales order or AP -> Inquiries -> History -> Voided Purchase order.

Now from this form you can only view the deleted orders but there is not option of restoring them.
Below are some sample code, you can use this to restore the voided orders.

Sales order restoration:
static void restoreDeletedSO(Args _args)
{
    SalesTableDelete    salesTableDelete;
    SalesLineDelete     salesLineDelete;
    SalesTable          salesTable;
    SalesLine           salesLine;
    ;

    SalesTableDelete = SalesTableDelete::find('00450_036', true);
    ttsbegin;
    switch (salesTableDelete.Cancelled)
    {
        case Voided::Voided :
            salesTable  = conpeek(salesTableDelete.SalesTable, 1);
            salesTable.insert();

            while select forupdate salesLineDelete where salesLineDelete.SalesId == salesTableDelete.SalesId
            {
                salesLine = conpeek(salesLineDelete.SalesLine, 1);
                salesLine.insert();
            }
            salesTableDelete.delete();
            break;

        case Voided::linesVoided :
            while select forupdate salesLineDelete where salesLineDelete.SalesId == salesTableDelete.SalesId
            {
                salesLine = conpeek(salesLineDelete.SalesLine, 1);
                salesLine.insert();
                salesLineDelete.delete();
            }
            salesTableDelete.delete();
            break;
   }

   ttscommit;
}


Purchase order restoration:





static void restoreDeletedPO(Args _args)
{
    PurchTableDelete    purchTableDelete;
    PurchLineDelete     purchLineDelete;
    PurchTable          purchTable;
    PurchLine           purchLine;
    ;

    purchTableDelete = PurchTableDelete::find('00242_049', true);
    ttsbegin;
    switch (purchTableDelete.Cancelled)
    {
        case Voided::Voided :
            purchTable  = conpeek(purchTableDelete.PurchTable, 1);
            purchTable.insert();

            while select forupdate purchLineDelete where purchLineDelete.PurchId == purchTableDelete.PurchId
            {
                purchLine = conpeek(purchLineDelete.PurchLine, 1);
                purchLine.insert();
            }
            purchTableDelete.delete();
            break;

        case Voided::linesVoided :
            while select forupdate purchLineDelete where purchLineDelete.PurchId == purchTableDelete.PurchId
            {
                purchLine = conpeek(purchLineDelete.PurchLine, 1);
                purchLine.insert();
                purchLineDelete.delete();
            }
            purchTableDelete.delete();
            break;
   }

   ttscommit;
}



If you have any query for the same feel free to ask.  
-Harry

September 22, 2012

AX 2012 – Data Migration Framework


AX 2012 – Data Migration Framework: Step-by-step setup

Recently i found a great blog on Data Migration Framework,
follow this link

AX 2012 – Data Migration Framework: Step-by-step setup

Its really help full for the step by step process of Data migration in AX 2009 to Ax 2012.

- Hary

September 10, 2012

How to send E-Mail In Microsoft Dynamics AX

How to send E-mail In  AX

There are more than one way to send emails through Microsoft Dynamics AX system, using X++ code.
The most recommended way is to use the standard mail mechanism built in the system.
That way copies of any email you send will be save in the Email sending status form (based on tableSysOutgoingEmailTable) and you will be able to monitor and see status of sent emails:

http://theaxapta.blogspot.in/

(Administration -> Periodic -> E-mail processing -> Email sending status; Form: SysOutgoingEmailTable)





This mechanism based on a system table that contain the emails, and a batch job that scan that table and send the emails, one by one (with retries and status controlling).
This technique is very simple to use and therefore it has some disadvantages; you cannot add attachments or use advanced email properties (cc, bcc, priority flag, etc).
To use this mechanism, first you have to make sure you a SMTP server configured and running.
Go to
  Administration -> Setup -> E-mail parameters 
and fill the required settings:



(Form: SysEmailParameters)

Next step is to make sure the E-mail distributor batch is up and running.
Go to
  Basic -> Inquiries -> Batch Job and check if the batch job exists with status Executing orWaiting.



(Form: BatchJob)
If it doesn’t, you can activate it from Administration -> Periodic -> E-mail processing -> Batch.
Now we are ready to implement our X++ code:
void SendMail()
{
    SysMailer mail;
    SysOutgoingEmailTable outgoingEmailTable;
    SysEmailItemId nextEmailItemId;
    Map map;
    str SenderName, SenderEmail, To, Subject, Body;
;

SenderName = "X++.info";
SenderEmail = "Sender@xplusplus.info";
To = "recipient@xplusplus.info";
Subject = "Subject line for the email";
Body = "<B>Body of the email</B>";

nextEmailItemId = EventInbox::nextEventId();
outgoingEmailTable.EmailItemId = nextEmailItemId;
outgoingEmailTable.IsSystemEmail = NoYes::No;
outgoingEmailTable.Sender = SenderEmail;
outgoingEmailTable.SenderName = SenderName;
outgoingEmailTable.Recipient = To;
outgoingEmailTable.Subject = SysEmailMessage::stringExpand(Subject, map);
outgoingEmailTable.Priority = eMailPriority::Normal ;
outgoingEmailTable.WithRetries = false;
outgoingEmailTable.RetryNum = 0;
outgoingEmailTable.UserId = curUserId();
outgoingEmailTable.Status = SysEmailStatus::Unsent;
outgoingEmailTable.Message = Body;
outgoingEmailTable.LatestStatusChangeDateTime = DateTimeUtil::getSystemDateTime();
outgoingEmailTable.insert();
}

The result of the example above will shown in the Email sending status form as mentioned above.



(Administration -> Periodic -> E-mail processing -> Email sending status; Form: SysOutgoingEmailTable)

- I Hope it will  usefull for all of you...
-Harry