Langsung ke konten utama

Postingan

Menampilkan postingan dari 2014

Example export data to excel in AX 2012

Example export data to excel in AX 2012 void exportToExcel() {     SysExcelApplication application;     SysExcelWorkBooks workbooks;     SysExcelWorkBook workbook;     SysExcelWorksheets worksheets;     sysExcelWorksheet worksheet;     SysExcelCells cells;     SysExcelCell cell;     int row;     ;     application = SysExcelApplication::construct();     workbooks = application.workbooks();     //gets the workbook object     workbook = workbooks.add();     // creates a new workbook     worksheets = workbook.worksheets();     //gets the worksheets object     worksheet = worksheets.itemFromNum(1);     //Selects the first worksheet in the workbook to insert data     cells = worksheet.cells();     cells.range('A:A').numberFormat('@'); // numberFormat ‘@’ is to insert data as Text     row = 1;         cell = cells.item(row,1);         cell.value("TransactionType");         cell = cells.item(row,2);         cell.value("StoreNumber&quo

How to filter records in a form by code

The standard filter functionality in Ax forms is a neat and powerful feature. Using this filter functionality in your code is something you'll definitely use at some point in time as a programmer. Although it's possible to do it in a single line of code, I prefer a 3 step solution. That way it's more flexible. Let me show you by example. We'll filter the customers records in form CustTable, only showing customers with currency USD. Step 1:  Declare a class variable In the  ClassDeclaration  method of the form, define a range. QueryBuildRange CurrencyQBR; Step 2:  Instantiate the new range. In the  init  method on the datasource of the form, you assign the range to a specific field (after the super call). public void init() { super(); CurrencyQBR = this.query().dataSourceName('CustTable').addRange(fieldnum(CustTable,Currency)); } Step 3:  In the last step, you assign a value to the range. This is done in the  executeQuery  method on the same datas

Error: An Unbalanced X++ TTSBEGIN/TTSCOMMIT pair has been detected... In AX

Error:  When trying to create a new record(s) in any table system shows following error eg. At the time of creating new Sales Order and this error may appear. Possible Reason(s): TTS level '1' usually leaves your Ax session in an unusable state that you can't close properly. Check all code for form or class from where this error comes and count the ttsbegin and ttscommit there must be same like if u write 2 ttsbegin u must have to write 2 ttscommit. Solution: To resolve this error this TTS level should be ZERO, Run this job to get rid of that error, this job will find the tts level where its greater than zero and make it zero by calling TTSABORT. static void TheAxaptaResetTTS(Args _args) {     while (appl.ttsLevel() > 0)     {         info(strfmt("Level %1 aborted",appl.ttsLevel()));         ttsAbort;     } } Other Info: ttsBegin : marks the beginning of a transaction. This ensures data integrity, and guarantees that all updates p

Get the filename from the File Path using X++

AX has a standard method in the Global Class to split the file name from the entire file path.The method is fileNameSplit().The method takes filepath as the parameter.It splits the filepath into three different strings filepath,filename,fileextension respectively.The usage of the function can be seen below. Filename filepath;  Filename filename;  Filename fileType;  str fileNameString; ; [filepath, filename, fileType] = fileNameSplit(fileNamePath);  fileNameString= filename + fileType;  Now the fileNameString will return you the filename with extension.

File open dialog on AX 2012 form

Problem: I want to show a file open dialog on AX 2012 form but when I click the open dialog button it doesn't respond. Solution: On Runbase OR Sys operations framework, all you have to do is set the EDT to FileNameOpen and dialog will appear, however, on AX form only setting the EDT will not do. You will need to add following methods to your form methods node. str filenameLookupFileName() {     return ""; } FilenameFilter filenameLookupFilter() {     return ["@SYS134052", #AllFilesName+#AllFilesExt]; } str filenameLookupInitialPath() {     return ""; } str filenameLookupTitle() {     return "Select a trade agreement to import"; }

How to read CSV files in AX 2012 through X++ code

Through following code we can read CSV files static void ReadCsvFile(Args _args) {     #File     IO  iO;     CustAccount custAccount;     CustName custname;     FilenameOpen        filename = "d:\\jit.csv";//To assign file name     Container           record;     boolean first = true;     ;     iO = new CommaTextIo(filename,#IO_Read);     if (! iO || iO.status() != IO_Status::Ok)     {         throw error("@SYS19358");     }     while (iO.status() == IO_Status::Ok)     {         record = iO.read();// To read file         if (record)         {             if (first)  //To skip header             {                 first = false;             }             else             {                          custAccount = conpeek(record, 1);//To peek record                 custname = conpeek(record, 2);                 info(strfmt('%1--%2',custAccount,custname));             }         }     } } or static void TestCommaTextIO(Args _args) { #File CommaT

A Simple Example : Sending Email with Attachment Using Phpmailer

PHPMailer is a PHP class that provides a package of functions to send email . The two primary features are sending HTML Email and e-mails with attachments . PHPMailer supports nearly all possiblities to send email :  mail()  , Sendmail  ,  qmail  & direct to SMTP server (ie sending email via your Google mail-account ) . You can use any feature of SMTP-based e-mail , multiple recepients via : to , CC , BCC , etc. In short: PHPMailer is an efficient way to send e-mail within PHP . As you may know, it is simple to send mails with the PHP  mail()  function . So why use PHPMailer ? Isn’t it slower ? Yes that’s true , but PHPMailer makes it easy to send e-mail , makes it possible to attach files , send HTML e-mail , etc . With PHPMailer you can even use your own SMTP server and avoid Sendmail routines used by the  mail()  function on *nix platforms . The following code snippet demonstrates how to implement the class into your script or website and how to build an e-mail application