Wednesday, 16 November 2016






How to convert AX to Excel using class x++


this is very easy example to learn that how to use excel class.
first need to create excel in your destination, and put the path in the bold letters. and run it .

static void AxtoExcel(Args _args)
{
    SysExcelApplication      sysExcelApplication;  //this is class
    SysExcelWorkBooks        sysExcelWorkBooks;    //this is class
    SysExcelWorkBook         sysExcelWorkBook;       //this is class
    SysExcelWorkSheets       sysExcelWorkSheets;      //this is class
    SysExcelWorkSheet        sysExcelWorkSheet;       //this is class
    SysExcelRange            sysExcelRange;           //this is class
    CustTable                custTable;
    int                      row = 1;
    str                      filename;
    ;

    // name of the file

    filename = "C:\\Users\akshay\Desktop\fa.xlsx";
    sysExcelApplication = sysExcelApplication::construct();


    // create excel workbook and worksheet
    sysExcelWorkBooks =  sysExcelApplication.workbooks();
    sysExcelWorkBook  =  sysExcelWorkBooks.add();

    SysExcelWorkSheets = sysExcelApplication.worksheets();
    SysExcelWorkSheet  = SysExcelWorkSheets.itemFromNum(1);

    //excel columns captions

    SysExcelWorkSheet.cells().item(row,1).value("Account");
    SysExcelWorkSheet.cells().item(row,2).value("Name");
    row++;

    //fill the custtable to excell

    while select custtable
    {
        if(row == 20) // this means to get only 20 row
        break;

        SysExcelWorkSheet.cells().item(row,1).value(custtable.AccountNum);
        SysExcelWorkSheet.cells().item(row,2).value(custtable.Name);
        row++;
        }

//Check whether the document already exists

   if(WinApi::fileExists(fileName))
      WinApi::deleteFile(fileName);

   //Save Excel document
   sysExcelWorkBook.saveAs(fileName);

   //Open Excel document
   sysExcelApplication.visible(true);
   //Close Excel
   //xlsApplication.quit();
   //xlsApplication.finalize();
}




Thanks

Akshay




Add true and false image on your form







Add true and false image on your form



Today i got little improvement. There i have to check qty is greater then another qty.
If it true then print right image or if false then print cross image front of qty field.

Let do this with minimum code.

  1.  First add window control in your form.
  2. Fill the properties like this




4. Now the right code in qualitycheckline table. Mathod.



display inventtestimage resultimage()
{
#resAppl
real total;
;
total = (this.EndQty /  minOne(this.qty())) * 100 ;
if(total < 10)
 return #Image_OK;

return #Image_NotOk;
}





Thanks

Akshay

Tuesday, 15 November 2016





Calculating code Execution time

This code is used to measure the code execution in millisecond and then convert in second.
Try to put this code in your code that you want to mesure.

public void GetExecutiontime()
{
int start;
int end;
int milliseconds;
real seconds;

;
start = winAPI::getTickCount();
sleep(1000);
end = winapi::getTickCount();
milliseconds = end - start;

seconds = milliseconds / 1000;
info(strfmt("total seconds - %1", seconds));
}


I put this code in my class then call this mathod in run mathod.

If you want to run this code in job then run .




Thanks


Akshay

Monday, 14 November 2016


How to add field lookup in your form.




Today i met i problem where i want to create a new line and select item from item field lookup .
But the problem is , client want he want to see item details which is filled in another form.

Example : one form RackInqueryForm , attach RackInqueryTable having these field

Now i want all the field in another form when i lookup by item id. in second form

Second form StockInOutForm .


Go to second form StockInOutForm -> datasource -> field itemid ->mathod -> overrides mathod.
Lookup mathod.

public void lookup(FormControl _formControl, str _filterStr)
{

   sysTableLookup  sysTableLookup = sysTableLookup::newParameters(tablenum(RackInqueryTable), _formControl);

   Query query;
   querybuildDatasource querybuildDatasource;
   ;

sysTableLookup.addLookupfield(fieldnum(RackInqueryTable, itemid),true);

sysTableLookup.addLookupfield(fieldnum(RackInqueryTable, itemname),true);

sysTableLookup.addLookupfield(fieldnum(RackInqueryTable, Rack),true);

sysTableLookup.addLookupfield(fieldnum(RackInqueryTable, Shelf),true);

sysTableLookup.addLookupfield(fieldnum(RackInqueryTable, Onhandrack),true);

sysTableLookup.addLookupfield(fieldnum(RackInqueryTable, RamainRackQty),true);

query  =new query();
queryBuildDataSource = query.addDataSource(tablenum(RackInqueryTable));

   // Add sorting index to query

   sysTableLookup.parmQuery(query);

   sysTableLookup.performFormLookup();




  // super(_formControl, _filterStr); // if this line is in not comment then it will lookup dual , //first your query and second default query
}





Thanks 

Akshay




Thursday, 10 November 2016



How to use jumpRef() / how to add go to main table or view details





Today i have add "go to main table" in my form field , in ax 2009 , this is also use full for AX 2012 user also becouse code are same, coding are same.just like view details in ax 2012

Example : i have created a form where i take item id and item name, qty.

now i have to add go to main table/view details on item id .

1. go to your created form,

2. select your form data source,

3. select field that you want to add this.

4. override jumpRef() mathod.

5. write this code according to your requirement.

public void jumpRef()
{
    inventtable inventtable;
    args args;
    menufunction mf;
    ;
// rackinquerytable.ItemId this is your table item id where you want to put this technique.//
// first need to match item id in both table//

    inventtable = inventtable::find(rackinquerytable.ItemId);
    if(!inventtable)
    {
    return ;
    }
    args = new args();
    args.caller(element);
    args.record(inventtable);
    mf = new menufunction(menuitemdisplaystr(inventtable),menuitemtype::Display);
    mf.run(args);

}



Thanks
Akshay

Wednesday, 2 November 2016





Get item name using item id (using active mathod and display mathod)

Today i am using active mathod to store item name in database table using display mathod.

Step1 . create table and take 2 string control one for itemid and second form itemname

Step 2. Write mathod in table mathod dispaly mathod name itemname

display itemname itemname()
{
inventtable inventtable;
;
return inventtable::find(this.ItemId).ItemName;
}

Step3. Now create form take both control and in itemid control datasource new table and datamathod name this display mathod itemname().
By this now when you select itemid , you will select itemname. But by this you will not see itemname in table.

For that

Step4. Form -> datasource mathod -> overwrite active mathod and write this code.

public int active()
{
   int ret;

   ret = super();
   
   RackInqueryTable.itemname = rackinquerytable.itemname();

   return ret;
}


Now you will see change in form and table too.



Thanks


Akshay





Automatic show on-hand inventory after selection particular item.(using modifiedField())


Today i am working on project. While making project i will meet simple requirement at every step .
Some time those who are new in Ax world , need basics , here one is simple technique to get item’s onhand  value on selection.



Step1 . create table name onhandtable.

Step2. Take itemid field and actualonhand field in real control.

Step3. In  table mathod overwrite mathod call modifiedField().

Step4 . and write code





Thanks

Akshay