Tuesday, August 28, 2012

Ax 2012 TableWithValidTimeStateFieldPropery


 


static void HKS_JobTableWithValidTimeStateField(Args _args)
{
    #AOT
    #properties
    TreeNodeIterator  treeNodeIterator;
    TreeNode             contextNode;
    str                        prop;
    int                        i;

    treeNodeIterator = TreeNode::findNode(#TablesPath).AOTiterator();
    contextNode = treeNodeIterator.next();
    while(contextNode)
    {
        contextNode = treeNodeIterator.next();
        prop =contextNode.AOTgetProperty(#PropertyValidTimeStateFieldType);
        if ( prop == enum2str(ValidTimeStateFieldType::Date) ||
            prop == enum2str(ValidTimeStateFieldType::UtcDateTime) )
        {
            info(contextNode.AOTname());
        }
    }
}








Ax 2012 Ax Util commands


 

run cmd

To clear screen cls

c:\ d:

d: \ cd "D:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities"
OR
In explorer go to D:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities
Click on the folder holding shift and select Open in "command window from here"

To list all the axutil commands:
------------------------------------
d:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities> axutil /?

To export the modal, If modal has space then use " "
-------------------------------------------------------------
d:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities>axutil export /model:hks1 /file:"C:\AxModal_Backup\hks1"

d:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities>axutil export /model:"USR Model" /file:"C:\AxModal_Backup\Usr Model"

To delete a model:
----------------------
d:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities>axutil delete /model:"hks1" /noPrompt

To delete a layer
d:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities>axutil delete /Layer:usr

To import a modal using Config
--------------------------------------
d:\Program Files\Microsoft Dynamics Ax\ManagementUtilitieses>axutil import /file:"C:\Axmodal_backup\hks.modal" /config:"DemoDataAx"

view modal contents based on model id
----------------------------------------------
D:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities>axutil view /model
:"28" /config:"DemoDataAx"
d:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities>axutil delete /model:"test12345" /noPrompt /config:"DemoDataAx"


Tuesday, March 27, 2012

Bread crumb bar event firing

 
//Add new variable and parm method to info class
Class declaration
boolean                 addressBarEvent; 

boolean parmAddressBarEvent(boolean _addressBarEvent = addressBarEvent)
{
    ;
    addressBarEvent = _addressBarEvent;
    return  addressBarEvent;
}

Do a forward compile

//Add a container object and parse the path to check if the user has selected change company option.
//If Yes, set the parm method info class.
\Classes\SysTaskRecorder_AddressbarEvents\fire_BreadcrumbBarNodeNavigate

    container   conStr;     infolog.parmAddressBarEvent(false);
    conStr = str2con(path,"\\");
    if (conlen(conStr)== 2)
        infolog.parmAddressBarEvent(true);
    
Do a forward compile

//In change default company check if the info parm method is set and perform the required action.
\Classes\Application\setDefaultCompany
    if (dialog)
    {
        //set the applicable user groups
        CAP_UserCompanyGroupServer::addUserGroupList();
        SysSecurity::reload(false);
        //infolog.runStartupMenu();
    }
    else if (infolog.parmAddressBarEvent())
    {
        //set the applicable user groups
        CAP_UserCompanyGroupServer::addUserGroupList();
        SysSecurity::reload(false);
        //infolog.runStartupMenu();
        infolog.parmAddressBarEvent(false);        
    }


Friday, March 16, 2012

Expr In Query For Dates

 
Class CustTransQueryAgingBucktetStat:


    str                     dateNull;
    Range                   rangeDocDate;
    date                    sqlFromDate;
    date                    sqlToDate;

    str date2SqlStr(date _date)
    {
        str sqlDate;

        if (_date == dateNull())
        {
            sqlDate = '01\\01\\1901';
        }
        else
        {
            if(_date == maxdate())
            {
                sqlDate = '31\\12\\2150';
            }
            else
            {
                sqlDate = date2str(_date, 123, 2, 3, 2, 3, 4);
                sqlDate = strReplace(sqlDate, '-', '\\');
            }
        }
        return sqlDate;
    }

    ;



    range = transDataSource.addRange(fieldnum(CustTrans, RecId));
    sqlFromDate = statementEndDate ? statementStartDate : dateNull();
    sqlToDate   = statementEndDate   ? statementEndDate   : maxdate();
    dateNull = date2StrXpp(dateNull());
    rangeDocDate  = '((DocumentDate >= ' + date2SqlStr(sqlFromDate) + ') &&';
    rangeDocDate += '(DocumentDate <= ' + date2SqlStr(sqlToDate) + ')) ||';
    rangeDocDate += '((DocumentDate = ' + dateNull + ') &&';
    rangeDocDate += '(TransDate >= ' + date2SqlStr(sqlFromDate) + ') && ';
    rangeDocDate += '(TransDate <= ' + date2SqlStr(sqlToDate) + '))';

    range.value(rangeDocDate);

Using joins in Query

void initParmDefault()
{
    Query                       query;
    QueryBuildDataSource        queryBuildDataSource,queryBuildDSProd;
    QueryBuildRange queryBuildRange,queryBuildRangeStatus;
    ;
    super();

    query = new Query();
    queryBuildDataSource = query.addDataSource(tablenum(InventTable));
    queryBuildDataSource.addSelectionField(fieldnum(InventTable, ItemId));
    queryBuildRange = queryBuildDataSource.addRange(fieldnum(InventTable, ItemType));
    queryBuildRange.value(SysQuery::value(ItemType::BOM));
    queryBuildRange.status(RangeStatus::Locked);
    queryBuildDataSource.addRange(fieldnum(InventTable, itemId));

    queryBuildDSProd = queryBuildDataSource.addDataSource(tablenum(ProdTable));
    queryBuildDSProd.addSelectionField(fieldnum(prodTable,itemId));
    queryBuildRangeStatus = queryBuildDSProd.addRange(fieldnum(ProdTable,ProdStatus));
    queryBuildRangeStatus.value(SysQuery::range(ProdStatus::Created,ProdStatus::StartedUp));
    queryBuildRangeStatus.status(RangeStatus::Locked);

    queryBuildDSProd.joinMode(JoinMode::ExistsJoin);
    queryBuildDSProd.fetchMode(QueryFetchMode::One2One);
    queryBuildDSProd.addLink(fieldnum(inventTable,itemid),fieldnum(prodTable,itemId));

    queryRun = new QueryRun(query);

    //QueryRun = new QueryRun(querystr(InventTable));


}

Using Expression in Query

Note: when string field is used in filteration then "" should be used. In the below example GroupId is string and when integer fields is used, no need to used "".
void queryFilter()
{
    AA_PriceDiscGroupBrand      priceDiscGroupBrand;
    str                         qbrValue,qbrGroupValue, qbrGroupValueAll;
    int                         relationVal;
    boolean                     recordFound = false;
    ;
    while select Type, GroupId from priceDiscGroupBrand  where
        (prevDate                >= priceDiscGroupBrand.FromDate  || ! priceDiscGroupBrand.FromDate)       &&
        (prevDate                  <= priceDiscGroupBrand.ToDate    || ! priceDiscGroupBrand.ToDate) &&
        priceDiscGroupBrand.CustAccount == custAccount

    {
        recordFound = true;
        if (priceDiscGroupBrand.Type == PriceGroupType::LineDiscGroup)
            relationVal = 5;
        if (priceDiscGroupBrand.Type == PriceGroupType::PriceGroup)
            relationVal = 4;

        qbrGroupValue = strFmt('(' +
                           '((%1.%2 == "%3") && (%1.%4 == %5) && (%1.%6 == %7))' +
                          ')',
                        this.query().dataSourceNo(1).name(),
                        fieldStr(PriceDiscTable,AccountRelation),
                        priceDiscGroupBrand.GroupId,
                        fieldStr(PriceDiscTable,AccountCode),
                        1,
                        fieldStr(PriceDiscTable,Relation),
                        relationVal
                        );
        if (!qbrGroupValueAll)
            qbrGroupValueAll = qbrGroupValue;
        else
            qbrGroupValueAll = qbrGroupValueAll + '||' + qbrGroupValue;
    }

    if (recordFound)
    {
        qbrGroupValueAll = '(' + qbrGroupValueAll + ')';
        qbrValue = strFmt('(' +
                          '((%1.%2 == "%3") && (%1.%4 == %5) && ((%1.%6 == %7) || (%1.%6 == %8)))'
                          + '||' +
                          '((%1.%2 == "%9") && (%1.%4 == %10) && ((%1.%6 == %7) || (%1.%6 == %8)))'
                          + '||' + qbrGroupValueAll +
                          ')',
                            this.query().dataSourceNo(1).name(),
                            fieldStr(PriceDiscTable,AccountRelation),
                            custAccount,
                            fieldStr(PriceDiscTable,AccountCode),
                            0,
                            fieldStr(PriceDiscTable,Relation),
                            4,5,
                            "",
                            2
                            );
    }
    else
    {

          qbrValue = strFmt('(' +
                          '((%1.%2 == "%3") && (%1.%4 == %5) && ((%1.%6 == %7) || (%1.%6 == %8)))'
                          + '||' +
                          '((%1.%2 == "%9") && (%1.%4 == %10) && ((%1.%6 == %7) || (%1.%6 == %8)))' + ')',
                            this.query().dataSourceNo(1).name(),
                            fieldStr(PriceDiscTable,AccountRelation),
                            custAccount,
                            fieldStr(PriceDiscTable,AccountCode),
                            0,
                            fieldStr(PriceDiscTable,Relation),
                            4,5,
                            "",
                            2
                            );
    }
    this.query().dataSourceNo(1).clearDynalinks();
    this.query().dataSourceNo(1).clearRanges();
    this.query().dataSourceTable(tableNum(PriceDiscTable)).addRange(fieldNum(PriceDiscTable,recid)).value(qbrValue);

}

Thursday, February 23, 2012

AllowEdit setting for all form datasource fields

 
void  AA_editSales()
{
    SysDictTable dictTable = new SysDictTable(tablenum(salestable));
    Counter      i;
    fieldId      fieldId;
    ;
    salesTable_ds.allowCreate  (false);
    salesTable_ds.allowEdit    (salesTableForm.editHeaderAllowed());
    salesTable_ds.allowDelete  (false);
    
    if (salesTableForm.editHeaderAllowed())
    {
        for (i=1; i<=dictTable.fieldCntWithoutSys() ;i++)
        {
            fieldId = dictTable.fieldCnt2Id(i);
            switch (fieldId)
            {
                case fieldnum(salestable,URL):
                
                    SalesTable_DS.object(dictTable.fieldCnt2Id(i)).allowEdit(true);
                    break;
                default:
                    SalesTable_DS.object(dictTable.fieldCnt2Id(i)).allowEdit(false);
            }

        }
    }
    
}

Calling menu string using args, formrun using args

 
Args args = new Args();

;

switch (_menuItemName)
{
    case menuitemoutputstr(PurchPackingSlipCopy) :
        args.record(vendPackingSlipJour);
        new Menufunction(menuitemoutputstr(PurchPackingSlipCopy),MenuItemType::Output).run(args);
    break;
    case menuitemoutputstr(PurchPackingSlipOriginal) :
        args.record(vendPackingSlipJour); 
        new Menufunction(menuitemoutputstr(PurchPackingSlipOriginal),MenuItemType::Output).run(args); 
    break; 
    case menuitemoutputstr(PurchPackingSlip) : 
        args.record(vendPackingSlipJour); 
        new Menufunction(menuitemoutputstr(PurchPackingSlip),MenuItemType::Output).run(args); 
    break;
} 


Args args = new Args(); 
FormRun formRun; 
; 
args.name( formstr(SalesTable) ); 
args.caller(this); args.record(salesTable); 
args.parm("OrderAmendment"); 
formRun = classFactory.formRunClass( args ); 
formRun.init(); 
formrun.run(); 
formrun.wait(); 

Wednesday, February 22, 2012

Connecting to Dynamics AOS Services on Remote destop

 
Here is a cool tip, if you don't want to connect to a remote computer where
the AOS is running to start and stop the AOS Services.
You can just go to Services, Right-click the services and 
click "Connect to another computer". 
The authentication (login) should be same for the current system and 
the Remote desktop.