Thursday, April 29, 2010

Copying a file from one location to other location using X++

 Copying a file using WINAPI Classes in AX2009

static void WinApiClassestocopythefile(Args _args)
{
    #avifiles
    boolean     present;
    SysOperationProgress    simpleProgress;
    int i;
    ;

   // startlengthyoperation();
    SimpleProgress = SysOperationProgress::newGeneral(#aviupdate, 'Simple', 100);
    if(WinAPI::fileExists("C:\\Documents and Settings\\nikhil.pujar\\My Documents\\Downloads\\ganatharva.pdf"))
    {
    for (i=1; i<=100; i++)
    {
        simpleProgress.incCount();
        simpleprogress.setText(strfmt("%1% Of File is being Copied",i));
        sleep(200);
    }
    WinAPI::copyFile("C:\\Documents and Settings\\nikhil.pujar\\My Documents\\Downloads\\ganatharva.pdf","C:\\Documents and Settings\\nikhil.pujar\\My Documents\\Morphx\\ganatharva.pdf",true);
    Simpleprogress.kill();
    }
    else
    {
        info("This file does not exist");
    }
    info("The file has been Copied :)");
    info(strfmt("The filesize is %1",WinApi::fileSize("C:\\Documents and Settings\\nikhil.pujar\\My Documents\\Morphx\\ganatharva.pdf")));
    info(WinAPI::getComputerName());
    //endlengthyoperation();
}

Tuesday, April 27, 2010

Check Credit Limit for a Sales Order

Credit Limit for a particular Sales Order can be checked as follows through the code

static void CreditLimit(Args _args)
{
    CustCreditLimit     custCreditLimit;
    SalesTable          salesTable;
    ;
    salesTable  =   SalesTable::find("SO-101297");
    info(strfmt("The SalesId is %1",salesTable.SalesId));
    custCreditLimit =   custCreditLimit::construct(salesTable);
    if(custCreditLimit.check())
    {
        info("Credit limit is OKZ");
    }
    info("Job Completed");
}

The Output is :


Emailing Techniques in Dynamics AX or Emailing through X++

E-mailing in Axapta

static void EmailSendingthroughSmmoutlook(Args _args)
{
   SmmOutlookEmail      smmOutlookEmail =   new     SmmOutlookEmail();
   str                  email;
   ;
   if (smmOutlookEmail.createMailItem())
   {
        smmOutlookEmail.addEMailRecipient('pujar.nikhil@gmail.com');
        smmOutlookEmail.addEMailRecipient('lincen_louis@yahoo.com');
        smmOutlookEmail.addSubject("Test Message from Axapta");
        smmOutlookEmail.isHTML(true);
        smmOutlookEmail.addBodyText('Hi Was just tryin to Send Email through Axapta           :)');
        smmOutlookEmail.sendEMail(smmSaveCopyofEmail::No);

    }
}

The above technique will use Microsoft Outlook and create a Email for you but will not send it Problematically you will have to hit send button if you want to send the email.

Here is another technique which will not only create an E-mail but will send also....    :)

    static void emailThruSysInetMail(Args _args)
    {
        SysInetMail mail = new SysInetMail();
        ;
        mail.sendMailAttach('lincen_louis@yahoo.com ', 'pujar.nikhil@gmail.com', 'Test mail from Axapta',         'Hi  There Was tryin to Send email through Axapta :)', false,"");
        SysInetMail::sendEMail('Alerts', 'en-us', 'nikhil.pujar@Solugenix.com');


    }

Thursday, April 22, 2010

Calculating the Sales Tax for a particular SalesOrder

Job for calculating SalesTax amount for particular Sales-Order

static void Calculatingtax(Args _args)
{
    SalesTotals     salesTotals;
    SalesTable              salesTable;
    TaxAmountCur        Amount;
    ;
    salesTable  =   SalesTable::find("SO-101242");
    salesTotals  = SalesTotals::construct(salesTable);
    Amount      = salesTotals.totalTaxAmount();
    info(Strfmt("The tax amount is %1",Amount));
}

The Output will be

Creating a Dialog in X++

Creating a Dialog in X++ or AX 2009

static void CreateDialog(Args _args)
{
  Dialog dailog= new Dialog("Nikhil");//(Created a object of Dialog class)
  Dialogfield field1,field2,field4,field3;//(objects of Dialog field Returns Dialogfield)
  DialogTabpage tab;//(object of DialogTabpage)
  ;
  field1=dailog.addField(typeid(Transdate));//(Parameter should be EDT or Enum)
  field2=dailog.addField(typeid(AccountName));
  field4=dailog.addField(typeid(CustName));

  tab   =dailog.addTabPage("Overview");//(Creates a new Tab Page )
  field3=dailog.addField(typeid(ABC)); //(Once you create Tab page All the fields after that will in     that )
  dailog.addGroup('Help');//(Creates a  Group)
  dailog.addField(typeid(ItemId));//(Now all the fields will be in Group Help)
  dailog.addText("I am Called"); //(adds text)

  if(dailog.run())//(Checks whether Dialog is running or not)
     {
    info(strfmt("%1,%2",field1.value(),field2.value()));//(Gives Value of field1 and field 2)
     }
}

The Output  will be as follows

Friday, April 16, 2010

Reading the SalesId from excel to post the SalesOrder using X++

Reading SalesId from Excel-sheet and then Posting it

static void ReadingSalesIdfromExcel(Args _args)
{
    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    COMVariantType type;
    SalesPosting    salesposting;   //Wrote my own class having a method Post to post a Sales Order.
    int row;
    SalesId salesId;
    #define.Filename('D:\\SalesOrders.xlsx')
    ;
    salesposting    =   new Salesposting();
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    try
    {
    workbooks.open(#Filename);
    }
    catch (Exception::Error)
    {
    throw error("File cannot be opened.");
    }
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    do
    {
    row++;
    salesId = cells.item(row, 1).value().bStr();
    salesposting.post(salesId);// Posting the Sales order with the help of SalesId from excel
    type = cells.item(row+1, 1).value().variantType();
    }
    while (type != COMVariantType::VT_EMPTY);
    application.quit();
}

Creating Sales order and Posting it through X++

Creating a Sales Order through X++

static void createsalesorder(Args _args)
{
    NumberSeq numberSeq;
    SalesTable salesTable;
    SalesLine salesLine;
    ;
    ttsbegin;
 numberSeq=NumberSeq::newGetNumFromCode(SalesParameters::numRefSalesId().numberSequence,true);
    salesTable.SalesId = numberSeq.num();
    salesTable.initValue();
    salesTable.CustAccount = '1301';
    salesTable.initFromCustTable();
    if(SalesTable.SalesId)
    {
    salesTable.insert();
    numberseq.used();
    }
    else
    {
    numberseq.abort();
    }
    salesLine.SalesId = salesTable.SalesId;
    salesLine.ItemId = '1101';
    salesline.SalesQty=100.00;
    salesLine.createLine(true, true, true, true, true, true);
    ttscommit;
}
And the next job is for Posting the above Sales Order Created


static void PostingsalesOrder(Args _args)
{
  SalesTable salesTable;
  SalesFormLetter salesFormLetter=salesFormLetter::construct(Documentstatus::Invoice);
  ;
  salesTable=salesTable::find("SO-101363");
  salesFormLetter.update(salesTable,SystemDateGet(),SalesUpdate::All,AccountOrder::None,false,false);
  info ("Invoice Successfully Generated");
}