Tuesday, 1 November 2011

How add financial dimension on forms inside Ax2012


1.      Perform
a)      Open AOT>>Data Dictionary>>Extended Data Types type/select DimensionDefault and drag it in table which will be used further as a datasource in form where you have to show the Dimensions. Do Remember  that you have to drag it in table not at DataSource.
b)     Open Table in the Data, Dictionary which will be used as a Datasource, and create a realtion with table DimensionAttributeValueSet .
c)      Right Click the Relations. Select ‘New Realation’.  Select properties. Set name as DimensionAttributeValueSet, Table as DimensionAttributeValueSet.
d)     Right Click the this newly created Relation DimensionAttributeValueSet, select New>>Normal.
e)      Set the properties of Normal Realtion as:  Field=TheFieldwhichwillsaveDimensionNumberInYourTable
Source EDT= DimensionDefault
Related Field=RecId

2.      Verify that the table that will hold the foreign key to the DimensionAttributeValueSet table is a
data source on the form(the one on which you have to show dimensions).
3.      Create a tab that will contain the financial dimensions control. This control is often the only
data shown on the tab because the number of financial dimensions can be large.
4.   set properties of Tab as under
a)      Set the Name metadata of the tab to TabFinancialDimensions.
b)     Set the AutoDeclaration metadata of the tab to Yes.
c)      Set the Caption metadata of the tab to @SYS101181 (Financial dimensions).
d)     Set the NeedPermission metadata of the tab to Manual.
e)      Set the HideIfEmpty metadata of the tab to No.
       5.  Override the pageActivated method on the new tab
public void pageActivated()
{
    dimDefaultingController.pageActivated();

    super();
}
      6.   Override the following methods on the form.
class declaration
public class FormRun extends ObjectRun
{
    DimensionDefaultingController dimDefaultingController;
}
init (for the form):
public void init()
{
    super();
    dimDefaultingController=DimensionDefaultingController::constructInTabWithValues(
      true, 
      true, 
      true, 
      0, 
      this, 
      tabFinancialDimensions, 
      "@SYS138487");

    dimDefaultingController.parmAttributeValueSetDataSource(myTable_ds,
    fieldstr(myTable, DefaultingDimension));
}
    7.      Override the following methods on the form data source
            public int active()
{
    int ret;
    ret = super();
    dimDefaultingController.activated();
    return ret;
}
public void write()
{
    dimDefaultingController.writing();
    super();
}
public void delete()
{
    
    super();
  dimDefaultingController.deleted();
}

           

Monday, 19 September 2011

what´s difference between Kernel version and Application


The Dynamics AX Kernel is the component executing the X++ Application code. So the Kernel version is the version of the executable (Client, Server, Business Connectors) while the Application version is the version of the Dynamics AX “Business Logic” - the X++ Application code, Forms, Repots – everything in the AOT.
You can check the current Application version in the Dynamics AX Client going to "Help - About Microsoft Dynamics AX".

Monday, 11 July 2011

Sample union query from AX 2009

Queries build with the Query classes now supports unions, meaning that you can combine the result from several tables into one result set. The results you want to combine from the different tables must be structured the same way for all tables.

You could for example create a query combining CustTable and VendTable. This would be particularly useful if you need to present for example a lookup form showing both customers and vendors in the same grid. In earlier version you’d have to push customer and vendor data to a temporary table before being able to present the combined data in one grid.

Here is an example on how to build and use a union query from X++:






static void union(Args _args)
{
    Query                query;
    QueryBuildDataSource qbdsCustTable;
    QueryBuildDataSource qbdsVendTable;
    QueryRun             queryRun;
    CustTable            custVendTable;
    Map                  mapTableBranches = new Map(types::Integer, typeId2Type(typeId(TableId)));
    SysDictTable         dictTable;
    ;


    // The map is used to match the UnionBranchID with a table id
    mapTableBranches.insert(1, tableNum(CustTable));
    mapTableBranches.insert(2, tableNum(VendTable));


    query = new Query();
    query.queryType(QueryType::Union);


    qbdsCustTable = query.addDataSource(tableNum(CustTable));
    qbdsCustTable.unionType(UnionType::UnionAll); // Include duplicate records
    qbdsCustTable.fields().dynamic(false);
    qbdsCustTable.fields().clearFieldList();
    qbdsCustTable.fields().addField(fieldNum(CustTable, AccountNum));
    qbdsCustTable.fields().addField(fieldNum(CustTable, Name));


    qbdsVendTable = query.addDataSource(tableNum(Vendtable));
    qbdsVendTable.unionType(UnionType::UnionAll); // Include duplicate records
    qbdsVendTable.fields().dynamic(false);
    qbdsVendTable.fields().clearFieldList();
    qbdsVendTable.fields().addField(fieldNum(VendTable, AccountNum));
    qbdsVendTable.fields().addField(fieldNum(VendTable, Name));


    queryRun = new QueryRun(query);
    queryRun.prompt();


    while (queryRun.next()) 
    {
        custVendTable = queryRun.getNo(1);
        dictTable = SysDictTable::newTableId(mapTableBranches.lookup(custVendTable.unionAllBranchId)); 


        info (strFmt("%1 %2 (%3)", custVendTable.AccountNum,
                                   custVendTable.Name,
                                   dictTable.name()));
    }
}


  

Tuesday, 17 May 2011

Who Modified Ax2009 Object?


Following code will help you that who have modified object last time with date. Copy code and paste it in job. 

static void UserWhoModifiedObjectLastDateandTime(Args _args)
{
UtilIdElements tblUtilIdElements;
;
while select tblUtilIdElements
where (tblUtilIdElements.utilLevel == UtilEntryLevel::USR && tblUtilIdElements.recordType == UtilElementType::Form && tblUtilIdElements.name == "SalesTable")

{

info(strfmt("%1",tblUtilIdElements.modifiedBy + " " + datetime2str(tblUtilIdElements.modifiedDateTime)));
}
}

Tuesday, 5 April 2011

How to check if your variable suit the conditions given in query range

Use inRange methods from Global class

static boolean inRange(str _rangeValue, anytype _value)

Example:

{

str _rangeValue;

str _value ;

boolean result;

;

_rangeValue = ‘200..500’;

_value = ‘300’;


result = Global::inRange (_rangeValue , _value);

}

The result variable will be equal to true


How to set focus when first time opening form in axpta

Override method firstField on a form, and call after super method setFocus of a control which should focused after form is opened. Example:

public void firstField(int _flags=1)
{
;
super(_flags);
MyControlName.setFocus();
}

How dynamically change data source field properties?

myTable_ds.object( fieldNum( myTable, myField ) ).visible( false );
myTable_ds.object( fieldNum( myTable, myField ) ).allowEdit( false );

How to override lookup in Ax2009?

Write following method on form level

void SummaryProjectLookup(FormControl ctrl)
{
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(ProjTable),ctrl);
Query query = New Query();
QueryBuildDataSource queryBuildDataSource = query.addDataSource(tableNum(ProjTable));
QueryBuildRange queryBuildRange;
;

sysTableLookup.addLookupfield(fieldNum(ProjTable, ProjId));
sysTableLookup.addLookupfield(fieldNum(ProjTable, Name));
sysTableLookup.addLookupfield(fieldNum(ProjTable, Status));

queryBuildRange = queryBuildDataSource.addRange(fieldNum(ProjTable, Type));
queryBuildRange.value(queryValue(ProjType::DEL_Summary));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
*******************************************************************
public void lookup()
{
element.SummaryProjectLookup(this);
}

Tuesday, 29 March 2011

How can I extract the hour, minute and seconds from AX2009 time?

static void time(Args _args)
{
TimeIn _TimeIn;
int hourInt, minuteInt , SecondInt;
str s;
;

_TimeIn = str2time('5:45');


s = time2str(_TimeIn,0,0);
info(strfmt("%1",s));

hourInt= str2int(substr(s,0,2));
info(strfmt("%1" ,hourInt));
minuteInt= str2int(substr(s,4,2));
info(strfmt("%1" ,minuteInt));
SecondInt= str2int(substr(s,7,2));
info(strfmt("%1" ,SecondInt));

}

Sunday, 27 March 2011

How to get current language of AX2009?

using following code

info( infolog.language());

How to refresh data source Table level method?

object Table1_ds;
;
Table1_ds = Table1.dataSource();

if(Table1_ds )

{
Table1.dataSource().refresh();
}


Sunday, 20 March 2011

How to refresh parent form data Source against child form button clicked

On Parent form data source write a method “refreshDatasource “

Step:1

void refreshDatasource ()

{

;

ParentTable_ds.research(true);

}

Step: 2

On child form click button write following code

Void Clicked

{

element.args().Caller().refreshDatasource();

}

Steps to Create Number Sequence on form using Table Level Methods in Microsoft Dynamics Ax2009

I will describe these steps with example in this example I have two Tables “Table1” and “Parameter Table” OR NumberSequenceReferenceone extend data type “Test” and “form1”.

Step1: Add one field in Table 1

Filed1 using extend data type Test

Write two methods on Table 1

Let suppose name are numberSeqFormHandleFiled1(Parameter1,Parameter2) and

formMethodDataSourceCreate(Parameter1,Parameter2)

Step 2: Write one method on Parameter Table OR NumberSequenceReference

numRefFiled1()

Detail code of all methods

static client server NumberSequenceReference numRefFiled1 ()

{;

return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(Test)));

}

***************************************************************************

public NumberSeqFormHandler numberSeqFormHandleFiled1 (FormRun _element, FormDataSource

_ Table 1_ds)

{

NumberSeqFormHandler numberSeqFormHandlerfiled1;

;

numberSeqFormHandlerfiled1= NumberSeqFormHandler::newForm(ParameterTable::numRefFiled1().NumberSequence,

_element,

_Table 1_ds,

fieldnum(Table1, Field1)

);

return numberSeqFormHandlerfiled1;

}

OR you can replace ParameterTable to NumberSequenceReference

numberSeqFormHandlerfiled1= NumberSeqFormHandler::newForm(NumberSequenceReference::numRefFiled1().NumberSequence,

_element,

_Table 1_ds,

fieldnum(Table1, Field1)

public void formMethodDataSourceCreate(FormRun _element, Object _Table1_ds)

{;

this.numberSeqFormHandlerField1(_element, _Table1_ds).formMethodDataSourceCreate();

}

Step 3: Drag Table1 on form1 as data source

Override “Create “ method of Table1 data source

In create method write following code

public void create(boolean _append = false)

{

;

super(_append);

Table1.formMethodDataSourceCreate(element,Table1_ds);

}