Monday 26 May 2014

How to change the tab order of the controls in axapta ?

There is the way, using code in the init
 (or calling a method which handles the tabOrder from init).

void init()
{
    Array tabOrder = new Array(Types::Integer);
    ;
    super();

    tabOrder.value(1, Control1.id());
    tabOrder.value(2, Control2.id());
    tabOrder.value(3, Control3.id());...etc

    element.tabOrder(tabOrder);
}

Friday 9 May 2014

Dynamics performance very slow in AX 2009

1. sql server activity monitor, kill all suspending transactions.
2. Go to the Administrations->Periodic->sql administration -index actions->press re-index for all tables
3. Administrations->Periodic->sql administration -table actions->Synchronize  your database 
4. restart all the servers like: application server, database server, etc,
hope it will increase performance .
http://blogs.msdn.com/b/axperf/archive/2008/03/13/ax-database-configuration-checklist-part-2.aspx

Tuesday 6 May 2014

Create and post Ledger Journal in ax 2009

static void ExampleLedgerJournal(Args _args)
{
    LedgerJournalName LedgerJournalName;
    LedgerJournalTable ledgerJournalTable;
    LedgerJournalTrans ledgerJournalTrans;
    LedgerJournalCheckPost ledgerJournalCheckPost;
    NumberSeq numberseq;
    LedgerJournalNameId LedgerJournalNameId = 'GenJrn';
    BankAccountID BankAccountID = 'CITI';
    ledgerAccount offsetAccount = '100000';
    amountCur amountCur = 102;
    ;
    ttsbegin;
    // Find a ledgerJournalName record
    select firstonly LedgerJournalName
    where LedgerJournalName.JournalName ==LedgerJournalNameId;
    //Created the ledgerJournalTable
    ledgerJournalTable.JournalName =LedgerJournalName.JournalName;
    ledgerJournalTable.initFromLedgerJournalName();
    ledgerJournalTable.Name = 'Hotel';
    ledgerJournalTable.insert();
    numberseq =NumberSeq::newGetVoucherFromCode(ledgerJournalName.VoucherSeries);
    ledgerJournalTrans.Voucher = numberseq.voucher();
    //Generate the transaction line
    ledgerJournalTrans.JournalNum =ledgerJournalTable.JournalNum;
    ledgerJournalTrans.CurrencyCode = 'EUR';
    ledgerJournalTrans.ExchRate =Currency::exchRate(ledgerJournalTrans.CurrencyCode);
    ledgerJournalTrans.AccountNum = BankAccountID;
    ledgerJournalTrans.AccountType =LedgerJournalACType::Bank;
    ledgerJournalTrans.AmountCurCredit = amountCur;
    //Pass the Date . You can also use str2Date('08/08/2008') if period is not defined.
    ledgerJournalTrans.TransDate = today();
    ledgerJournalTrans.Txt = 'Room Stay';
    ledgerJournalTrans.OffsetAccount = offsetAccount;
    ledgerJournalTrans.OffsetAccountType =LedgerJournalACType::Ledger;
    ledgerJournalTrans.insert();
    info(strfmt('Journal Id:%1',ledgerJournalTable.JournalNum));
    //Post the Journal
   // ledgerJournalCheckPost= ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,NoYes::Yes);
   // ledgerJournalCheckPost.run();
    ttscommit;
}



static void enterPostLedgerJournal(Args _args)
{
LedgerJournalName ledgerJournalName;
LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalCheckPost ledgerJournalCheckPost;
NumberSeq numberSeq;
;
ttsbegin;
ledgerJournalName = LedgerJournalName::find("GenJrn");
ledgerJournalTable.initFromLedgerJournalName(ledgerJournalName.JournalName);
ledgerJournalTable.insert();
numberSeq = NumberSeq::newGetVoucherFromCode(ledgerJournalName.VoucherSeries);
ledgerJournalTrans.voucher = numberSeq.voucher();
ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
ledgerJournalTrans.currencyCode = 'USD';
ledgerJournalTrans.ExchRate =Currency::exchRate(ledgerJournalTrans.currencyCode);
ledgerJournalTrans.AccountNum = '140550';
ledgerJournalTrans.AccountType = ledgerJournalACType::Ledger;
ledgerJournalTrans.AmountCurDebit = 1220.00;
ledgerJournalTrans.TransDate = systemdateget();
ledgerJournalTrans.Txt = 'Projector sold';
ledgerJournalTrans.OffsetAccount = '401140';
// Insert to records into the ledgerJournalTrans table
ledgerJournalTrans.insert();
// Use the LedgerJournalCheckPost class to
// post the journal
ledgerJournalCheckPost =LedgerJournalCheckPost::construct(LedgerJournalType::Daily);
// Set the JournalId, tableId of the journalTable
// and specify to post the journal (not only check it).
ledgerJournalCheckPost.parmJournalNum(ledgerJournalTable.JournalNum);
ledgerJournalCheckPost.parmPost(NoYes::Yes);
ledgerJournalCheckPost.run();
ttscommit;
}

http://ax2012xppdataimport.blogspot.in/

ODBC Connection Inbound in ax 2009

1.Set DSN connection.
2.static void ODBCConnectionInbound(Args _args)
  {
    LoginProperty   loginProp,loginProp1;
    ODBCConnection  conn,conn1;
    Resultset       resultSet, resultSetCount;
    Statement       statement1, statement2;
    TimeExpected    timeExpected;
    SqlStatementExecutePermission perm;
    N_LedgerJournal1  LedgerJournal,LedgerJournallocal;
    int    counter;
    str   value;
    container c;
    int i;
    #AviFiles
    str sql,valuesql;
    SysOperationProgress progress = new SysOperationProgress();
    ;

    loginProp = new LoginProperty();
    loginProp1 = new LoginProperty();
    loginProp.setServer('INAXSRV');
    loginProp.setDatabase('N_HS_Testing');
    loginProp1.setServer('INAXSRV');
    loginProp1.setDatabase('N_HS_Testing');
    conn = new ODBCConnection(loginProp);
    conn1 = new ODBCConnection(loginProp1);
    statement1  = conn.createStatement();
    statement2  = conn1.createStatement();

    perm = new SQLStatementExecutePermission("SELECT * FROM [N_HS_Testing].[dbo].[AX_LEDGERJOURNAL] where flag =0 and CENTER_ID =1 and [CREATED_DATE] >='"+'2011-05-01 00:00:00.000'+ "'and [CREATED_DATE] <='"+'2011-05-31 00:00:00.000'+"' ");
    perm.assert();
    resultSet   = statement1.executeQuery("SELECT * FROM [N_HS_Testing].[dbo].[AX_LEDGERJOURNAL] where flag =0 and CENTER_ID =1 and [CREATED_DATE] >='"+'2011-05-01 00:00:00.000'+"'and [CREATED_DATE] <='"+'2011-05-31 00:00:00.000'+"' ");
    resultSetCount = resultSet;
    progress.setCaption("Progress bar example…");
    progress.setAnimation(#AviUpdate);
    progress.setTotal(254360);
    ttsbegin;
    while (resultSet.next())
    {
        i++;
        counter++;
        LedgerJournal.LedgerGerneral_Id  = resultSet.getString(1);
        LedgerJournal.JournalNum         = resultSet.getString(2);
        LedgerJournal.JournalName        = resultSet.getString(3);
        LedgerJournal.DateTime           = resultSet.getDateTime(5);
        LedgerJournal.CenterId           = any2int(resultSet.getInt64(8));
        LedgerJournal.insert();
      //  this.Journaltransentry(LedgerJournal.JournalNum);
        sql = "update  [N_HS_Testing].[dbo].[AX_LEDGERJOURNAL] set flag =1 where flag =0  and [LEDGERGENERAL_ID] = '" + LedgerJournal.LedgerGerneral_Id + "';";
        statement2.executeUpdate(sql);
        progress.setText(strfmt("The value of i is %1", i));
        progress.setCount(i, 1);
       /* if(counter==1)
        {
            break;
        }*/
    }
    ttscommit;
    info('successfully imported');
    info(strfmt('%1',i));
    CodeAccessPermission::revertAssert();
}

Saturday 3 May 2014

Open Table Browser in ax 2009

static void TableBrowser(Args _args)
{
SysTableBrowser sysTableBrowser = new SysTableBrowser();
;
//Browse the SalesTable table
sysTableBrowser.run(tablenum(NWH_LedgerJournal1 ));
}

TO Get last Info log event in ax 2009

static void LastInfoLog(Args _args)
{
    int i;
    str messageBody;
    ;
    try
    {
       info("In the 'try' block. (j1)");
       info("infolog!");
       throw warning("test warning");
       throw error("test error");
       info("infolog!");
       throw warning("test warning");
        //throw Exception::Error;
    }
    catch
    {
        for (i=1; i<=infolog.line(); i++)
        {
            messageBody = ":" + infolog.text(i);
        }
    }
    info(messageBody);
}

static void TOGetLasteventlog(Args _args)
{
    SysInfologEnumerator enumerator;
    SysInfologEnumerator enumeratorlocal;
    SysInfologMessageStruct msgStruct;
    Exception exception;
    int i,j;
    str  text,Textlocal,textmsg;
    int line = infolog.line();
;
    try
    {
       info("In the 'try' block. (j1)");
       info("infolog!");
       throw error("test error");
       throw warning("test warning");
       info("infolog!");
       throw warning("test warning");
        //throw Exception::Error;
    }
    catch (Exception::Error)
    {
        enumerator = SysInfologEnumerator::newData(infolog.cut());
        while (enumerator.moveNext())
        {
            msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
            exception = enumerator.currentException();
            text =strfmt('%1',exception);
            Textlocal = strfmt('%1',msgStruct.preFixTextElement(1));
            textmsg   = strfmt('%1',msgStruct.message());
            //  info(strFmt("Type: %1; Prefix: %2; Message: %3",exception,msgStruct.preFixTextElement(1),  msgStruct.message()));
        }
        info(strFmt("Type: %1; Prefix: %2; Message: %3",text,Textlocal,  textmsg));
    }
    catch (Exception::Info)
    {
        enumerator = SysInfologEnumerator::newData(infolog.cut());
        while (enumerator.moveNext())
        {
            msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
            exception = enumerator.currentException();
            text =strfmt('%1',exception);
            Textlocal = strfmt('%1',msgStruct.preFixTextElement(1));
            textmsg   = strfmt('%1',msgStruct.message());
            //  info(strFmt("Type: %1; Prefix: %2; Message: %3",exception,msgStruct.preFixTextElement(1),  msgStruct.message()));
        }
        info(strFmt("Type: %1; Prefix: %2; Message: %3",text,Textlocal,  textmsg));
    }
    catch (Exception::Warning)
    {
        enumerator = SysInfologEnumerator::newData(infolog.cut());
        while (enumerator.moveNext())
        {
            msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
            exception = enumerator.currentException();
            text =strfmt('%1',exception);
            Textlocal = strfmt('%1',msgStruct.preFixTextElement(1));
            textmsg   = strfmt('%1',msgStruct.message());
            //  info(strFmt("Type: %1; Prefix: %2; Message: %3",exception,msgStruct.preFixTextElement(1),  msgStruct.message()));
        }
        info(strFmt("Type: %1; Prefix: %2; Message: %3",text,Textlocal,  textmsg));
    }
    catch (Exception::Warning)
    {
        enumerator = SysInfologEnumerator::newData(infolog.cut());
        while (enumerator.moveNext())
        {
            msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
            exception = enumerator.currentException();
            text =strfmt('%1',exception);
            Textlocal = strfmt('%1',msgStruct.preFixTextElement(1));
            textmsg   = strfmt('%1',msgStruct.message());
            //  info(strFmt("Type: %1; Prefix: %2; Message: %3",exception,msgStruct.preFixTextElement(1),  msgStruct.message()));
        }
        info(strFmt("Type: %1; Prefix: %2; Message: %3",text,Textlocal,  textmsg));
    }
    infolog.clear(line);
   /* enumerator = SysInfologEnumerator::newData(infolog.cut());
    while (enumerator.moveNext())
    {
            msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
            exception = enumerator.currentException();
            text =strfmt('%1',exception);
            Textlocal = strfmt('%1',msgStruct.preFixTextElement(1));
            textmsg   = strfmt('%1',msgStruct.message());
          //  info(strFmt("Type: %1; Prefix: %2; Message: %3",exception,msgStruct.preFixTextElement(1),  msgStruct.message()));
    }
     info(strFmt("Type: %1; Prefix: %2; Message: %3",text,Textlocal,  textmsg));*/
}
In ax  2012:-
str errorMessage;
  
try
{
    throw error('Some error message being thrown here');
}
catch
{
    errorMessage = infolog.text(infologLine());
}
  
print errorMessage;
  
pause;