Tuesday, March 26, 2013

Lookup form for the Enum field

Creates and shows a lookup form for the Enum field for the Document Type based on reference type.
Ex: If reference type is Purchase,  document type enum should only have options blank, Product receipt, Receipt list, registration.
If reference type is Sales,  document type enum should only have options blank, Packing slip, Picking list

Refer the Quality Association form (Inventory and warehouse management > Setup >Quality Control > Quality Association)
Form InventTestAssociationTable
QualityOrderGeneration_M_edit_documentType:Lookup method which calls the  inventTestAssociationTable.lookupDocumentType(this);
edit method on table is used to show the enum values.

Wednesday, March 13, 2013

Ax 2012 Export / import Labels

Create a new notepad and add the below commands and save the file as with .bat extention to run as batch job.
cls 
del D:\Test\TstLabel.axmodel
cd /D D:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities 
axutil export /model:"TST" /file:"D:\Test\TstLabel" /config:"Dynax_SIS" 
axutil import /file:"D:\Test\TstLabel" /config:"Dynax_SIS" /noPrompt 
Pause 

The 1st command clears the screen.
The 2nd command is used delete the file if the file already exists where we want to export the file.
The 3rd command will change the directory to where the Ax util tool is available. Check the path and ensure it is set to write file path.
The 4th command will export the model "tst" to the file path mentioned from the configuration file (AOS server). 
The 5th command will import the file to desired configuration (AOS server). Ensure the required model is available in the new AOS configuration. 
Also modal will be imported to the same layer as it was exported.
The 6th command will wait for user for user to press any key. This will help to check whether the export and import executed successfully.

Monday, March 11, 2013

Ax 2012 Hide Financial dimensions.

Requirement: If we need to not show one or more financial dimensions in any required form.
We need to hide a financial dimension in customer master.
Soln:
Create a new table to hold the dimension attribute and primary table name of the form in which we want to hide the dimension.















Insert records into the table.
 


\









Modify the DimensionDefaultingControllerBase and DimensionDefaultingController class Class\DimensionDefaultingControllerBase ClassDeclaration()












setupEditAreaControls()
HKS_DimAttributeHide HKS_DimAttributeHide; //Add new variable
Add the below code.

loadAttributeSet()
HKS_DimAttributeHide HKS_DimAttributeHide; //Add new variable
Add the below code.

Class\DimensionDefaultingController
parmAttributeValueSetDataSource()
Set the enumstableName to the calling table datasource (In the above example, this will be custTable). enumstableName = _dataSource.table(); //hks

Open the custTable form and check the financial dimensions. VendorGroup and ItemGroup will not be displayed.
Open any other form (ex: vendTable) and check the financial dimensions. All dimensions should be visible.


Friday, March 1, 2013

Ax 2012 changing financial dimensions

static void HKS_defaultSODimension(Args _args)
{

    DimensionAttribute                    dimensionAttribute;
    DimensionAttributeValue               dimAttributeValue; 
    DimensionAttributeValueSetStorage    dimensionAttributeValueSetStorage;
    DimensionAttributeValueSetItem       dimensionAttributeValueSetItem; 
    DimensionAttributeValueSet            dimAttrValueSet; //Stores the Hash value based on the combination of Atttibutes values. If no record found, new record is created.
    SalesTable                            salesTable;

    recId                           defaultDim;
    TableId                         viewId;

    viewId = tableNum("DimAttributeSalesTable");

    select firstonly  dimensionAttribute where dimensionAttribute.BackingEntityType == viewId;
    //dimensionAttribute = DimensionAttribute::findByName("VendorGroup"); //find the attribute table.
    dimAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,"20",false,true); //get the Attribute value table. If the value is not found create a new one.

    salesTable = salesTable::find("SO-100605");
    dimensionAttributeValueSetStorage = dimensionAttributeValueSetStorage::find(salesTable.DefaultDimension); 
    //if ( !dimensionAttributeValueSetStorage.getDisplayValueByDimensionAttribute(dimensionAttribute.RecId))
    if (dimAttributeValue) //Check if the attribute value is valid.
    {    
        //checkif the attribute value is already exisitng as part of hash value in dimensionAttributeValueSetStorage
        if (!dimensionAttributeValueSetStorage.containsDimensionAttributeValue(dimAttributeValue.RecId)) 
        {
            dimensionAttributeValueSetStorage.addItem(dimAttributeValue);
            defaultDim =  dimensionAttributeValueSetStorage.save();
            update_recordSet salesTable setting  DefaultDimension =  defaultDim where salesTable.SalesId == "SO-100605"; //update the reference dimension.
        }
    }
}