Monday, December 26, 2016

Code to check document is attached in AX

static void AlfasithCheckAttacheddocu(Args _args)
{
    PurchTable             PurchTable; //Table your concern
    DocuRef                 DocuRef;
    ;
    select purchTable where purchTable.PurchId == "45655"; // Table your concern
    select DocuRef where DocuRef.RefTableId == PurchTable.TableId
                    &&  DocuRef.RefRecId == PurchTable.RecId;
   
    info(DocuRef.Name);
    pause;
}

Convert UTCDateTime to date & date to UTCDateTime in x++

print DateTimeUtil::newDateTime(today(), 0, DateTimeUtil::getCompanyTimeZone());
    // Here today() is the date format not utcdatetime format...


    print DateTimeUtil::date(UTCFieldValue);
    // Here UTCFieldValue is theUTC date time field...


    //Get date diff from 1 UTC date time and another date type in AX
    return DateTimeutil::getDifference(
                        DateTimeUtil::newDateTime(resRentAgreement.StartDate, 0,       DateTimeUtil::getCompanyTimeZone()),
                        resGracePeriodHistory.createdDateTime))
// here resRentAgreement is the date field and resGracePeriodHistory is UTCDateTime field.

Code to get multi selected records in from grid in X++

void clicked()
{

     int             ListOfRecIds, i=1;
    container  contains;
    CustTable  custTableLoc; // Table_Name  that we used in as the datasource.
    super();
   
    ListOfRecIds= custTable_ds.recordsMarked().lastIndex();
    custTableLoc= custTable_ds.getFirst(1);
   
   while (custTableLoc)
    {
        contains = conIns(container, i ,custTableLoc.AccountNum)
       custTableLoc = custTable_ds.getNext();
        i++;
    }
 }

Access the other instance DB belongs to same domain but different DB in x++

static void AlfasithOtherDBAccess(Args _args)
{
    LoginProperty       loginProp;
    ODBCConnection      conn;
    Resultset           resultSet, resultSetCount; // get record
    Statement           statement1, statement2; // Create SQL Statement
    ResultSetMetaData   metaData ; // get Record metadate like columnname.
    RetailTillLayout    RetailTillLayout;
    int i = 1;
    ;

    // Set Server Database
    loginProp = new LoginProperty();
    loginProp.setServer('DNWADY0046L'); // System or  server name
    loginProp.setDatabase('MicrosoftDynamicsAX'); // instance DB name like MicrosoftDynamicsAX_Live

    // Create Connection and SQL Statement
    conn = new ODBCConnection(loginProp);
    statement1 = conn.createStatement();
    resultSet = statement1.executeQuery("SELECT TOP 1 * from [MicrosoftDynamicsAX].[dbo].[RetailTillLayout]");

    while (resultSet.next())
    {
        metaData = resultSet.getMetaData();
        while (i)
        {
            info("Column Name :"+metaData.getColumnName(i)+ " Value = "+resultSet.getString(i));
            i++;
        }
    }
}

Code to print Ledger journal balance in X++

static void AlfasithPrintLedgerBalance(Args _args)

{

    LedgerBalanceMainAccountAmounts balance;

    MainAccountListPageBalanceParameters balanceParameters;

    MainAccount mainAccount;

    ;

    mainAccount = MainAccount::findByMainAccountId( "11120005");

    balanceParameters = MainAccountListPageBalanceParameters::construct();

    balance = LedgerBalanceMainAccountAmounts::construct();



    balance.parmAccountingDateRange(balanceParameters.getStartDate(),balanceParameters.getEndDate());

    balance.parmPostingLayer(balanceParameters.getPostingLayer());

    balance.parmIncludeOpeningPeriod(balanceParameters.getIncludeOpeningPeriods());

    balance.parmIncludeRegularPeriod(balanceParameters.getIncludeOperatingPeriods());

    balance.parmIncludeClosingPeriod(balanceParameters.getIncludeClosingPeriods());

    balance.parmIncludeClosingPeriodBySystem(balanceParameters.getIncludeClosingPeriods());


    balance.calculateBalance(mainAccount);


    info(strFmt("%1", balance.getAccountingCurrencyBalance()));

}

Code to refresh AOT in AX

public server static void refreshServer()
{
    #AOT ;
    TreeNode::findNode(#TablesPath).AOTrefresh();
    TreeNode::findNode(#TableMapsPath).AOTrefresh();
    TreeNode::findNode(#ViewsPath).AOTrefresh();
    TreeNode::findNode(#ExtendedDataTypesPath).AOTrefresh();
    TreeNode::findNode(#BaseEnumsPath).AOTrefresh();
    TreeNode::findNode(#LicenseCodesPath).AOTrefresh();
    TreeNode::findNode(#ConfigurationKeysPath).AOTrefresh();
    TreeNode::findNode(#SecurityKeysPath).AOTrefresh();
    TreeNode::findNode(#TableCollectionsPath).AOTrefresh();
    TreeNode::findNode(#PerspectivesPath).AOTrefresh();
    TreeNode::findNode(#MacrosPath).AOTrefresh();
    TreeNode::findNode(#ClassesPath).AOTrefresh();
    TreeNode::findNode(#ReportsPath).AOTrefresh();
    TreeNode::findNode(#ReportTemplatesPath).AOTrefresh();
    TreeNode::findNode(#SectionTemplatesPath).AOTrefresh();
    TreeNode::findNode(#QueriesPath).AOTrefresh();
    TreeNode::findNode(#JobsPath).AOTrefresh();
    Dictionary::aodFlush();
    Dictionary::dataFlush();
    flush UtilElements, UtilIdElements;
}

Code to refresh AOS and remove *.AOC files in AX

static server void refreshAOS(Args _args)
{
    ;

    xSession::removeAOC();
    SysTreeNode::refreshAll();
    SysFlushDictionary::doFlush();
    SysFlushAOD::doFlush();
    xSession::updateAOC();
}