Tuesday, April 21, 2015

Dimension in Ax 2012

Understanding the dimensions on ledgerJournalTrans

LedgerJournalTrans has 4 dimensions fields: LedgerDimension, DefaultDimension, OffSetLedgerDimension and offSetDefaultDimension.

You can think of LedgerDimension and OffSetLedgerDimension as holding an account and the dimensions for that account, both in one field. Where as the DefaultDimension and the OffSetDefaultDimension only holds the dimension.

The Fields LedgerDimension and OffSetLedgerDimension are shown in the form as “Account” and “Offset account”. The fields DefaultDimension and OffSetDefaultDimension are shown in the form under the button “Financial Dimension/Account” and “Financial Dimension/Offset Account”.



Which of the fields you have to fill out, depends on the fields Accounttype and OffSetAccountType:
AccountType = Ledger  a fill out LedgerDimension with a mainAccount and dimensions
AccountType = not Ledger a fill out ledgerDimentin with an account (ex CustAccount) and fill out DefaultDimension with dimensions.
OffSetAccountType = Ledger a fill out OffSetLedgerDimension with a mainAccount and dimensions
OffSetAccountType = not Ledger a fill out OffSetledgerDimentin with an account (ex CustAccount) and fill out OffSetDefaultDimension with dimensions.

Look at the example below. The Customer DAT-000001 has dimension show in the form “Enter account financial dimension”. DAT-000001 is info stored in the LedgerDimension and the dimensioninformation is stored in the DefaultDimension. The offset ledgeraccount is 1000 and both this information and the dimensions are shown in the “Offset account” field and stored in the OffSetLedgerDimension. OffSetDefaultDimension is blank.


Upgrading the dimensions in LedgerJournalTrans
Then upgrading the code concerning ledgerJournalTrans it is important to remember, that you need to make sure that both the account and the offset account have there dimensionsfields filled out and that the dimensions are the same, as this is how it was in Ax 4.0.

Ex:
Old code
newJournalTrans.Dimension[6]           = TUSParameter::find().FinDep_DimTransactionTypeId;
newJournalTrans.OffsetAccountType =  LedgerJournalACType::Ledger;
newJournalTrans.OffsetAccount         =  tusFinDepEntrySetup.PreliminaryDebtAccount;

New code:
//old code - newJournalTrans.Dimension[6] = TUSParameter::find().FinDep_DimTransactionTypeId;

//newJournalTrans.DefaultDimension   = newJournalTrans.DefaultDimension merged with TUSParameter::find().FinDep_DimTransactionTypeId as the TransactionType attribute

tusTransactionsType=transactionsType::find(TUSParameter::find().FinDep_DimTransactionTypeId);
newJournalTrans.DefaultDimesion= TUSDimensionServices::addOneTusDimToADefaultDimension
(newJournalTrans.DefaultDimension, DimensionAttribute::getDimAttributeTUSTransactionType(), tusTransactionsType.TransactionType, tusTransactionsType.RecId);
newJournalTrans.OffsetAccountType   = LedgerJournalACType::Ledger;

//old code - newJournalTrans.OffsetAccount  = tusFinDepEntrySetup.PreliminaryDebtAccount;

newJournalTrans.OffSetledgerDimension = DimensionDefaultingEngine::getLedgerDimensionFromAccountAndDim(
                                               mainAccountRecId,
                                               DimensionHierarchy::getAccountStructure(mainAccountRecId),
                                               newJournalTrans.DefaultDimension);

How to add dimension on forms

Table - we need to create defaultdimension field with Edt as DimensionDefault and create relation with DimensionAttributeValueSet (Recid) to the DefaultDimension field.

Form - we need to add the table to the datasource part. In the Design side we need to create FinancialDimension Tab with Empty Fields.

Code - we need to write the code in following Methods

Class Declaration

public class FormRun extends ObjectRun
{
    DimensionDefaultingController       dimensionDefaultingController;
}
This object does the work in handling the dimensions. And it does it without that much work from our site.
init
public void init()
{
    boolean financialsDimensionsEnabled = true;
    super();
    dimensionDefaultingController = DimensionDefaultingController::constructInTabWithValues(false, true, financialsDimensionsEnabled, 0, this, tabFinancialDimensions, "@SYS138491");
    dimensionDefaultingController.parmAttributeValueSetDataSource(KbDimensionTab_ds, fieldStr(KbDimensionTab, defaultdimension));
    dimensionDefaultingController.parmValidateBlockedForManualEntry(true);

    tabFinancialDimensions.enabled(financialsDimensionsEnabled);
}
The first line instantiates the object which takes – among others – the formRun and the empty tab page as parameters.
The second line tells the class what data source and which field on the table it should use when handling the financial dimensions.
The third activates the class. If you have the dimensions on a separate tab page on your form you can call the pageActivated method when that tab page is activated to increase performance.
write
public void write()
{
    super();
     dimensionDefaultingController.writing();
}
active
public int active()
{
    int ret;

    ret = super();
    dimensionDefaultingController.activated();

    return ret;
}
delete
public void delete()
{
    super();
    dimensionDefaultingController.deleted();
}
pageactivated
public void pageActivated()
{
    dimensionDefaultingController.pageActivated();

    super();
}

DAVS- it stores recid of dimension
DAVSI - recid of value .
how to add dimensions on tables

1) Create New table and EDT of Dimension Default to your table.
2) Set the relation of DimensionAttributValueSet table (Recid field) to your table of DimensionDefault.



once create the table as shown above. we need to create View for your table
3) Create View for your table named as DimensionAttributeKbDimension
4) Change the Datasource name as BackingEntity
5) drag the Itemname,Tracking no and Recid to the Field and changed name as Name,Value and Key for the 3 fields.


5) Create and run the following  job to clear the dimension cache:
static void clearCache(Args _args)

{
DimensionCache::clearAllScopes();
info("done");
}


6)GL--Setup--FinancialDimension.Click new and select your table name from the use values from field.


7) enter the dimension name for your table.e.g KbDimension
8) click the financial dimension button for your KbDimension.

9) see the financial dimension form for your table.here we can see yourtable data of itemname and trackingno field.

10) Goto GL--Setup---Chart of Accounts--configure account structures.
11) select anyone of structure. i have selected Account structure P&L and click the edit button.
select the ADD Segement.


12) once selected the value and click ADD Segement button. automatically coloumn will added to the form as shown below

13) finally, click the activate button.


https://sumitsaxfactor.wordpress.com/2011/12/16/getting-individual-dimension-combination-valuesdimension-storage-class-ax-2012/








Friday, April 17, 2015

Number Sequence

1) we need to create EDT as string KBNumSeqCustGroupNum.
2) we need to add code for the particular module. so we have to choose which module we are going to add number sequence.in this case ,am going to add in customer module.Class--NumberSeqModuleCustomer--LoadModule Method






3) Go to OA-Common-Number Sequence . Click Generate Button



Click the details button below and set or change the value as you like in the number sequence, highest and lowest and format.


Click finish button


Go to the Custgroup table and added KBNumSeqCustGroupNum edt to the field and set the allow edit as NO. add the KBNumSeqCustGroupNum edt to overviewgroup in the table.



open the custgroup form. add the following codes .

  1. Write the following code on the Class declaration node
     NumberSeqFormHandler numberSeqFormHandler;

  2. Create a new method on the form and write the following code
    NumberSeqFormHandler numberSeqFormHandler(){
    if (!numberSeqFormHandler){
    //create a reference of number sequence form handler class specifying the         EDT, Data source name and the field of the table
    numberSeqFormHandler =NumberSeqFormHandler::newForm(NumberSeqReference::findReference(extendedtypenum(KBNumSeqCustGroupNum)).NumberSequenceId, element,CustGroup_DS,fieldnum(CustGroup,KBNumSeqCustGroupNum));}return numberSeqFormHandler;
    }

  3. Override the close method of the form and write the following code
    public void close()
    {
        if (numberSeqFormHandler)
        {
            numberSeqFormHandler.formMethodClose();
        }
        super();
    }

  4. Override the create method on the CustGroup data source and add the following code
    public void create(boolean _append = false){
    element.numberSeqFormHandler().formMethodDataSourceCreatePre();
    super(_append);
    element.numberSeqFormHandler().formMethodDataSourceCreate(true);}

  5. Override the write method on the CustGroup data source and add the following code
    public void write(){
    super();
    element.numberSeqFormHandler().formMethodDataSourceWrite();}

  6. Override the validateWrite method on the CustGroup data source and add the following code
    public boolean validateWrite(){
    boolean ret;
    ret = super();
    ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret;
    return ret;}

  7. Override the delete method on the CustGroup data source and add the following code
    public
    void delete()
    {
    element.numberSeqFormHandler().formMethodDataSourceDelete();
    super();}

  8. Override the linkActive method on the CustGroup data source and add the following code
    public
    void linkActive()
    {
    element.numberSeqFormHandler().formMethodDataSourceLinkActive();
    super();}
  9.  once we complete the above procedure, just open the custGroup form and click new button automatically number sequence field is added as well as number filled.
http://www.dynamics101.com/2014/09/creating-custom-number-sequences-microsoft-dynamics-ax-2012/

Query in X++ code and AOT

  1. There are two ways to create queries:
  2. 1. Create Static Query using a graphical interface.
  3. 2. Dynamic queries by x++ code using System class.


Statics Query


How to add select button on RunBaseBatch Using Static Query on class.using RunBaseQueryDialog to display the select button on form.


 Simple class.

1) HrmAbsenceCreateTables- is a query.
    HRMAbsenceCreateTables - is a class
    HCMWorker,HCMEmployment,DirPerson - tables are used in the query.

2) WorkCalendarDelete,WmsOrderFinish


3) RunbaseBatch Class without Select button
    Class - EventJobDueDate

4) Inheritance Class
    HcmSkillChartDepartment,HcmSkillGapByJobSkill


Example

5) Table - EcoResColor-lookupProductVariantColor

6) SSRS Class - AssetBalancesPeriodDP, BankAccountStatementDp ,SalesOrderEntryStatisticsDP,
SalesOrderEntryStatisticsContract, SalesOrderEntryStatisticsController.
7) Forms - VendSearchCriterion,VendSearchAddCategory.
.

Dynamic Query

  1. construct query by using X++ code.
JmgPayEventsExport(Method :BuildEmployeeQuery) class is the example of query.

InventUpdate class implements Query to wrire Business logic.

https://community.dynamics.com/ax/b/daxmusings/archive/2011/09/27/query-and-new-related-objects-in-ax-2012.aspx

Wednesday, April 15, 2015

Types Of Lookup In Ax 2012

EDT Lookup

First we need to create table
VetSpeciesTable
1) SpeciesID
2) Name
second we need to create primary index for speciesID , so set allow duplicate vale as No
third we need to set Primary index as speciesid

Create EDT for the Species and set the referencetable. for clear idea , i ill show the below screen shot.





once we have complete the procedure, if we use the above edt speciesID to any  table automatically foreignkey relation will create to current table.we ill get lookup of the table.



Create lookup in form without creating a method from table

Standard Example of code

Lookup in queries

\Forms\DirPartyQuickCreateForm\Data Sources\LogisticsPostalAddress\Fields\CountryRegionId\Methods\lookup


Output of the above code

AR-- All Customers-- Create customers


Creating Custom Lookup Dynamically by using Queries


VendTable we ill write one lookup method to display the additional with the existing lookup.

now we are going to write one lookup method and after that we are going to call this method in form.


Code
public void lookupVendorByCurrency(FormControl _formControl, Currencycode _currency)
{
    Query               query;
    QueryBuildDataSource qbds;
    QueryBuildRange      qbr;
    SysTableLookup      sysTableLookup;

    query = new Query();
    sysTableLookup = SysTableLookup::newParameters(tableNum(VendTable), _formControl,true);
    query.addDataSource(tableNum(VendTable));
    qbr = qbds.addRange(fieldNum(VendTable,Currency));
    qbr.value(queryValue(_currency));
    sysTableLookup.addLookupfield(fieldNum(VendTable,AccountNum),true);
    sysTableLookup.addLookupfield(fieldNum(VendTable,Party));
    sysTableLookup.addLookupfield(fieldNum(VendTable,Currency));
 

    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}

Go to the Cust table form and click datasource custtable and field vendaccount .create lookup method for thgat field

public void lookup(FormControl _formControl, str _filterStr)
{
    VendTable::lookupVendorByCurrency(_formControl,CustTable.Currency);
}



Output

AR-- All customers--edit button-- Miscellaqneous Details group--vendor account filed

Previously it used to disaplay vendaccount and name.. now we added the currency field in the existing lookup.




Lookup by args

Standard Form Name :AssetDepBookLVPTransferProposal(\Forms\AssetDepBookLVPTransferProposal\Designs\DesignList\TransferToAssetId\Methods\lookup)

Table:Assettable(lookupAccountNumLVP Method)

Tuesday, April 14, 2015

Table properties - Support Inheritance,Extends,Abstract

Example

If you want to set the supportinhertiance to the table,
Step 1;
Create table
set the property as yes to SupportInheritance(before create any filed to the table)
Set yes to Abstract
create new filed as InstanceRelationType by the datatype as Int64
set the InstanceRelationType to the property InstanceRelationProperty

EcoResProduct - Base Table
EcoResProductMaster - Child Table
EcoResDistinctProduct -Child table


In the child table we need to set the property Base table  to Extend and set yes to support inheritance.
You cant create the same name of field in the child table which is already exist in the parent table.



http://axdaily.blogspot.com/2011/04/table-inheritance.html

Thursday, April 9, 2015

Info part in Form

How to create infor part in form

First we need to create query. in this query we need to add tables anf fields.
second we need to add info part in AOT.

Data Dicitionary- Index and Relations

Index
Unique Index
Non Unique Index

Unique Index
 To set an index as a unique index, you can set the index property called allow duplicates to no.  Fields should not to allow edit.To set an index as the alternate key, you can set the alternate key property of the index to yes.Set the primary Index property to the unique index.When a primary index is not specified, AX uses a surrogate key as the primary index. 


The ClusterIndex value is given to the underlying Microsoft SQL Server database system as a performance tuning choice. This choice generally controls the physical sequence in which the records are stored in the underlying database.


Relations
Normal 

 Normal specifies related fields in another table.  Multiple fields can be included in this relation.






Field Fixed

Field fixed and related field fixed are conditional relations.  Conditional relationships can be created by adding a condition to a table relation.  Only records that fulfill the condition are included in the relation. A condition on a relation filters the records on either the table that contains the relation or the related table, depending on the type of condition.  Field fixed specifies that the condition is on the table that contains the relation

https://dynamicsaxinsight.wordpress.com/2014/01/23/conditional-relations-with-field-fixed-and-related-field-fixed/

Related Field Fixed







In the above example you can see the related field example. first one relations is created in the cust table for custvenditemgroup table and field of module.

Module is Enum data type, so invent is first value, so if we create new record in the custvenditemgroup table automatically 1 value is assigned to Module field.

Foreign Key

http://axdaily.blogspot.com/2011/05/surrogate-keys-in-ax-2012.html