Wednesday, March 8, 2017

Shrinking log file on sql database in Ax

Shrinking log file on sql database


1.First open SQL Database------>right click MicrosoftDynamicsAx----click properties to check file size

2.Then for safety purpose ----->right click MicrosoftDynamicsAx------>Task----->Backup,

3.And remove the existing path and add your desired path location.


4.Then click MicrosoftDynamicsAx----->Right click ----> Newquery


5.Then the page display like this

6.In this Page add your db shrinking code 

USE MicrosoftDynamicsAX;
ALTER DATABASE MicrosoftDynamicsAX
SET RECOVERY SIMPLE;
DBCC SHRINKFILE (MicrosoftDynamicsAX_Log, 0);
ALTER DATABASE MicrosoftDynamicsAX
SET RECOVERY FULL


7.Click Execute on top of the page

8.The Database will be shrinked and reduced into small. 
  

Sunday, March 5, 2017

How to reset "unbalanced ttsbegin ttscomit " error in ax 2012

To reset "Unbalanced ttsbegin ttscommit pair has been detected" error in AX 2012

//Write this code in Job and Run.

static void TheAxaptaResetTTS(Args _args)
{
    while (appl.ttsLevel() > 0)
    {
        info(strfmt("Level %1 aborted",appl.ttsLevel()));
        ttsAbort;
    }
}

Saturday, March 4, 2017

Form Methods in Ax 2012

Sequence of form Methods:

This gives the information of method calls in the form level while
1. Opening the Form.
2. Creating/Updating/Deleting the record in the Form.
3. Closing the Form.


Sequence of Methods calls while opening the Form

Form — init ()
Form — Datasource — init ()
Form — run ()
Form — Datasource — execute Query ()
Form — Datasource — active ()


Sequence of Methods calls while closing the Form


Form — canClose ()
Form — close ()

Sequence of Methods calls while creating the record in the Form


Form — Datasource — create ()
Form — Datasource — initValue ()
Table — initValue ()
Form — Datasource — active ()

Sequence of Method calls while saving the record in the Form


Form — Datasource — ValidateWrite ()
Table — ValidateWrite ()
Form — Datasource — write ()
Table — insert ()

Sequence of Method calls while deleting the record in the Form


Form — Datasource — validatedelete ()
Table — validatedelete ()
Table — delete ()
Form — Datasource — active ()

Sequence of Methods calls while modifying the fields in the Form

Table — validateField ()
Table — modifiedField ()

Thursday, March 2, 2017

Sequence Of Table Methods in Ax 2012

   Sequence Of Table Methods



    When you press CTR+N

    inItValue()

    When you change data in a Field

    validateField()  -> validateFieldValue() ->  ModifiedField() ->  ModifiedFieldValue()

    When you close the table after entering some data

    validateWrite() - > Insert()  -> aosValidateInsert()

    When you open the table which will contain some data
    If table will contain 10 records this method is called 10 times

    aosValidateRead()

    When you Save the Record for the first time

    validateWrite() ->Insert() - > aosValidateInsert()

    When you modify the record and saving

    validateWrite() -> update() - > aosValidateUpdate()

    When you delete the record

    validateDelete() -> delete() -> aosValidateDelete()

Wednesday, March 1, 2017

Import From Excel File Using X++ in AX 2012



In this example i have my customized table ImportTable with the following fields
(itemid,qty,price,purchunit,lineamount)



static void ImportFromExcel(Args _args)
{
Dialog _dialog;
DialogField _file;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
Name name;
FileName filename;
ImportTable importTable; //Declaring Table Name
int  row = 1;
str   _itemid;
real  _qty;
real  _price;
str   _purchunit;
real  _lineamount;

_dialog = new Dialog("Please select the file to load");
_dialog.addText("Select file:");
_file   = _dialog.addField(ExtendedTypeStr("FilenameOpen"));
_dialog.run();

if (_dialog.closedOK())
{
info(_file.value() );

application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename =_file.value(); //ExcelSheet File Name
try
{
     workbooks.open(filename);
}
catch (Exception::Error)
{
     throw error('File cannot be opened');
}

workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1); //Here 1 is the worksheet Number
cells = worksheet.cells();
do
{
        row++;
        _itemid     = cells.item(row, 1).value().bStr();
        _qty         = cells.item(row, 2).value().double();
        _price       = cells.item(row, 3).value().double();
        _purchunit   = cells.item(row, 4).value().bStr();
        _lineamount  = cells.item(row, 5).value().double();

        importTable.ItemId       = _itemid;
        importTable.Qty          = _qty;
        importTable.Price        = _price;
        importTable.PurchUnit    = _purchunit;
        importTable.LineAmount   = _lineamount;
        importTable.insert();
        type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
info("Data is Imported");
}
}

Find Onhand Qty by ItemId In X++ code

On Hand Qty by ItemId:



static void onhandcode(Args _args)
{
InventOnhand  inventOnhand;
InventDim     inventDim;
InventDimParm inventDimParm;
ItemId        itemId;
InventQty     availqty;

itemId = "1102";

inventDimParm.initFromInventDim(inventDim);

inventOnhand = inventOnhand::newParameters(itemId,inventDim,inventDimParm);
availqty = inventOnhand.availPhysical();
info(strFmt("%1",availqty));

}