Pages

Wednesday, 24 September 2014

Creating A Record in CustTrans Form During An Invoice Process In Sales Order Form

                            Classes------>SalesFormLetter_Invoice------>createCustTrans() Method Will Start the Process.
                            Class--------------->CustVendVoucher------>post()  Method Will Do The Insert....

Another Easiest Way Is Go To Tables---->CustTrans----->insert() method you will Give which field you want to flown from CustTable To CustTrans Table.....

creating the Map:
                          create  new fields in both table CustTable,CustTrans Tables   and then go ------>AOT------>DataDictionary------>Map---->Select the CustTrans--->add fields in custTrans mapping fields....
select Mapping ---->Give Mapped Field property --> to Remarks fields.
Goto Class----->CustVoucher---->In initCustTransTable--->Add code 

custTrans.Remarks = custTable::Find(custTrans.AccountNum).Remarks;

thats it

For Example...
Creating a new field as Remarks in CustTable and also same way to create Remark field in CustTrans.I mean customer form - transactions button
when we post sales order invoice, I want customer table remarks to be flown to customer transactions form .....So just go to table custTrans open the insert method  and paste the following code....

this .Remarks = custTable::find(this.OrderAccount).Remarks;

Thats it......

Monday, 22 September 2014

Freezing Multiple Records In Dynamics Ax 2009

In Some time we want to freeze or read only for current active records.Here am showing hoe to freeze multiple records at one shot.

Example:

Write Following Code In form Design Button Click
---------------------------------------------
void clicked()
{
   ProductInform productInform1,productInform2;
    Container con,conrec;
    int i ;

    ;
    productInform2 = ProductInform_DS.getFirst();
    productInform1 = ProductInform_DS.getFirst();
    i = 1;

    for(productInform1 = ProductInform_DS.getFirst(true) ? ProductInform_DS.getFirst(true) : ProductInform_DS.cursor() ;
        productInform1; productInform1 = ProductInform_DS.getNext() )
        {
            con = conIns(con,i,productInform1.Status);
            conrec = conIns(conrec,i,productInform1.RecId);


            if(conPeek(con,i) != 0)
            {
                throw error("You are not selected Open Order");
            }
            i++;
        }
    ttsbegin;
    if(i == 2)
    {

        select forupdate productInform1 where productInform1.RecId == productInform2.RecId;

        if(productInform1)
        {
            productInform1.Status = statusIdea::Posted;
            productInform1.Permissions = permissions::No;
            productInform1.update();
        }
        ProductInform_DS.reread();
        ProductInform_DS.refresh();
        ProductInform_DS.active();

    }
    else
    {
        for(productInform2 = ProductInform_Ds.getFirst(1) ? ProductInform_DS.getFirst(1) : productInform2 ;productInform2; productInform2 = ProductInform_DS.getNext())
        {
            select forupdate productInform1 where productInform1.RecId == productInform2.recId;

            if(productInform)
            {
                productInform1.Status = StatusIdea::Posted;
                productInform1.Permissions = permissions::No;
                productInform1.update();
            }
        }

    ProductInform_DS.research(true);
    }
    ttscommit;

    super();
}

----------------------------------------------------------------
Write Following Code In Form DataSource Active Method
------------------------------------------------------------

public int active()
{
    int ret;
    ;
    ret = super();

    if(ProductInform.Permissions == permissions::No)
    {

        ProductInform_DS.allowEdit(false);
        Button.enabled(false);

    }
    else
    {
        ProductInform_DS.allowEdit(true);
        Button.enabled(true);
    }


    return ret;
}

Wednesday, 17 September 2014

X++ Code For Run a Form Using Class Factory

Class FormRunUsingClassFactory
{
    Args args;
    FormRun formRun;
}

Void CallingForm()
{
   args = New Args(FormStr(CustTable));////Here Mention the Name of the Form
   formRun = ClassFactory.FormRunClass(args);
   formRun.init();
   formRun.run();
   formRun.detach();
}

Public Static Void Main(Args args)
{
   FormRunUsingClassFactory formcf;
   ;
   formcf = New FormRunUsingClassFactory();
   formcf.CallingForm();
}








Converting Date to UTCTimeDate

SomeTime we need to converting  normal SystemDate to UtcDateTime.Here Am show you how to convert that date.In Dynamics Ax having some Class DateTimeUtil.

Example:

              DateTimeUtil::NewDateTime(today(),0,DateTimeUtil::getCompanyTimeZone()));


Static void DateConvert(Args _args)
{
                info(strfmt("%1",DateTimeUtil::newDateTime(today(),0,DateTimeUtil::getCompanyTimeZone())));

}

Tuesday, 9 September 2014

Create & Posting For Free Text Invoice Through X++ code in Ax Dynamics 2009

      A free text invoice is an invoice that is not attached to a sales order. A free text invoice contains a header and one or more lines for items or services that are not tracked in inventory. Use a free text invoice for sales that do not require a sales order, packing slip, and customer invoice. For example, you can use a free text invoice for a consulting fee or services fee, or for a miscellaneous fee for an event reimbursement. 

     In Short Sales Invoice is transaction where Inventory will come into picture.. and For Free text invoice there is no relation of inventory in its Transaction. 

     Here using Tables are CustInvoiceTable and CustInvoiceLine && Class name is CustPostInvoice.It will be used for posting the data to free text invoice Table..

Examples

Public Static FreeTextInvoice(Args args)
{
         CustInvoiceTable      custInvoiceTable;
         CustInvoiceLine        custInvoiceLine;
         CustPostInvoice        custPostInvoice; 
         CustTable                  custTable;
         LedgerTable              ledgerTable;
         LineNum                    lineNum;
         ;

         //Inserting the values to CustInvoiceTable
         ttsbegin;
         custTable = CustTable::find('CustAccountNumber');//Example accountNumber:1000,3003 like wise
         custInvoiceTable.initFormCustTable(custTable);
         custInvoiceTable.insert();  
         ttscommit;
         
         //Inserting the values to CustInvoiceTable  

         ledgerTable = LedgerTable::find('ledgerAccountNumber');
         custInvoiceLine.clear();
         custInvoiceLine.initValue(); 
         custInvoiceLine.LedgerAccount = ledgerTable.AccountNum;
         custInvoiceLine.initFormCustInvoiceTable(ledgerTable);
         custInvoiceLine.AmountCur = 1000;
         custInvoiceLine.Description = "GoodWill";
         custInvoiceLine.TaxItemGroup = 'Full';
         custInvoiceLine.ParentRecId    = custInvoiceTable.RecId; 
         if(!lineNum)
         {
                lineNum = CustInvoiceLine::lastLineNum(custInvoieLine.ParentRecId); 
         } 
         lineNum += 1;
         custInvoiceLine.LineNum = lineNum;
         custInvoiceLine.insert();
         ttscommit; 
         
         //Posting to FreeTextInvoice class is called for Posting
          
         custPostInvoice = new CustPostInvoice(custInvoiceTable);
         custPostInvoice.run();
          
}



 

Sending An Email With Error Exception

          In Order to Sending an Email in Dynamics Ax 2009.First we have to configure the Email Template in Basic---->Setup---->Email Template.
Email Template Form Will be Open.So here Give a Sender Email address and description in that form and creating a new template for your message.........
In Dynamics Ax having a class SmmOutLookEmail for sending email through OutLook..


Example:

static void sendEmailNormal(Args _args)
{
    Description             recipientEmail;
    Notes                   emailBody;
    Description             subjectText;
    Filename                fileName;
    SmmOutlookEmail         smmOutlookEmail = new SmmOutlookEmail();
    Log     log;
    int i=1;
    container con;
    SysInfologEnumerator enum ;
    ;
    recipientEmail = "YourRecipientEmailAddress";
    subjectText     = "Test Email";
    info( "CustTable ");
    error('Syntax Error');
    error('UnReachable codes');
    log = Info::infoCon2Str( infolog.copy(1,infolog.num()));
    con = infolog.copy(1,infolog.num());
    enum = SysInfologEnumerator::newData(con );
    emailBody       = "Hi,\nThis is a test email.\nThanks.\n";
    while (enum.moveNext())
    {
        emailBody +=strfmt('%1 -> %2 ',int2str(enum.currentException()), enum.currentMessage());
    }


    if (smmOutlookEmail.createMailItem())
    {
        smmOutlookEmail.addEMailRecipient(recipientEmail);
        smmOutlookEmail.addSubject(subjectText);
     // smmOutlookEmail.addFileAsAttachment(fileName);
        smmOutlookEmail.addBodyText(emailBody);
        smmOutlookEmail.sendEMail(smmSaveCopyOfEMail::No);
    }
    else
    {
        error("Could not communicate with Microsoft Outlook Client.");
    }

}


  

Delete & Copy The File in Dynamics Ax 2009

           
               Sometimes we have to write the same data from one file into another file.So we waste a  lot of time in it.In Dynamics Ax having special way to do that through WINAPI class.Here am showing you how to copy the files and delete the old files...... before we doing this we add File IO permission for file name with Read/Write permissions.....


Formats:
             WINAPI::CopyFile("SourceFilePathName","DestinationFilePathName",BooleanValues);
             WINAPI::DeleteFile("SourceFilePathName");

             (or)
             System.IO.File::Copy("SourceFilePathName","DestinationFilePathName",BooleanValues);
             System.IO.File::Delete("SourceFilePathName");

Example;


static void wpicopy(Args _args)
{
      ;
    winApi::copyFile(@"E:\AxDynamics\car.txt",@"E:\AxDynamics\carIdValues.txt",true);
    winApi::deleteFile(@"E:\AxDynamics\car.txt");
 
}


It will Supporting to Copy the  All File Types like an Excel,Txt,Xml......