Thursday, November 8, 2012

Calculation of the item average availability


Hi all!

This time I will talk to you about the way to calculate average availability over time in AX 2009.

The calculation of the average availability requires the availability of every item code on a specific date (usually at the end of month), but this information seems not available directly in AX 2009.

I found a way to retrieve this information: I create a batch class that runs every day and check if the current day is the last day of the month.
For doing this check I have used the "endMth" function, that works also with leap years

Here's the code:

void Run()
{
    Table1                         table1;
    TransDate                   t = today();
    TransDate                   lastdayofMth;
    ;

    lastdayofMth = endmth(t);
    if (t==lastdayofMth)
    {
       //Insert your code here for populate a custom table with item availability
    }
}

This is part of a custom project I developed for get the Inventory Turnover Index in AX 2009.
(if anyone is interested please do not hesitate to contact me).

See you next time!...



Friday, November 2, 2012

Passing values between two forms


Hi all!

Today i will talk to you about passing values between forms in AX...
We have to open a form with data filtered by specific parameters coming from another form.

In this specific case I have to pass ItemId and InventDimId from InventDimCombination (formA) to a custom-made form (formB).

First I created a MenuItemButton on formA which calls FormB and I override the clicked method with this code:

void clicked()
{
    Args            _args;
    FormRun         _formRun;
    str             _filterValue;
    ;

    //Assign at _filterValue a string that contains ItemId and InventDimId in a unique field which is
    //pass to the next form
    _filterValue = (InventDimCombination.ItemId + '-' + InventDimCombination.InventDimId); 
    _args   = new Args();
    // _filterValue is passed to next form
    _args.parm(_filterValue);
    _args.name(formstr(formB));
    _args.caller(this);

    // Creating object for FormRun and initialization for load
    _formRun = ClassFactory.formRunClass(_args);
    _formRun.init();
    _formRun.run();
    _formRun.wait();
}

Then I override the init method of the formB datasource:

public void init()
{
    QueryBuildRange     rangeItemId;
    QueryBuildRange     rangeConfigId;
    QueryBuildRange     rangeColorId;
    str                 Config;
    str                 Color;
    str                 s,t;
    int                 i;
   
    super();
   
    //check if value is arrived from formA
    if(element.args().parm())
    {
     //retrieve ItemId and InventDimId as two separate field from the passed value
     i      = strlen(element.args().parm());
     s      = substr(element.args().parm(),i-7,8);//inventDimId
     t      = strDel(element.args().parm(),i-8,9);//ItemId
     Config = InventDim::find(s).configId;
     Color  = InventDim::find(s).InventColorId;
   
    //create the query to initialize the form
    rangeItemId   = this.query().dataSourceTable(tablenum(formBtable)).addRange(fieldnum(formBTable, ItemIdfield));
    rangeConfigId = this.query().dataSourceTable(tablenum(formBtable)).addRange(fieldnum(formBtable, ConfigIdfield));
    rangeColorId  = this.query().dataSourceTable(tablenum(formBtable)).addRange(fieldnum(formBtable, InventColorIdfield));
    rangeItemId.value(t);
    rangeConfigId.value(Config);
    rangeColorId.value(Color);
    rangeItemId.status(RangeStatus::Hidden);
    rangeConfigId.status(RangeStatus::Hidden);
    rangeColorId.status(RangeStatus::Hidden);
    }
}

That's all, when you press the button in formA, the formB will open showing only data related to the passed parameters

See you next time!