18 December 2019

From date and toDate query ranges in Report and form X++ code in AX 2012

Below logic can be used for filtering using from date and to date.

dateRange.value(SysQuery::range(FromDate.dateValue(), ToDate.dateValue()));

Form level in the execute query can write the below logic.

QueryBuildRange dateRange = SysQuery::findOrCreateRange(this.queryBuildDataSource(), fieldNum(MyTable, MyDateField));

26 November 2019

SysOperation frame work in D365 F&O example with batch job

class TRGBatchService extends SysOperationServiceBase { /// <summary> /// /// </summary> /// //[SysEntryPoint(false)] private void processCode() { Info("Test"); } }

class TRGBatchController extends sysOperationServiceController
{
  public static void main(Args args)
    {
        TRGBatchController controller = new TRGBatchController(classStr(TRGBatchService),methodStr(TRGBatchService,processCode),SysOperationExecutionMode::Synchronous);
        controller.startOperation();
    }

    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    public ClassDescription caption()
    {
        ClassDescription ret;
    
        ret ="Operation batch job";
    
        return ret;
    }


}

14 November 2019

Sequence of methods in the FORM level in AX / Form opening sequences in AX 2012 D365


Sequence of methods in the FORM level in AX / Form opening sequences in AX 2012 D365

Sequence of Methods calls while opening the Form
Form --- init ()
Form --- Datasource --- init ()
Form --- run ()
Form --- Datasource --- execute Query ()
Form --- Datasource --- active ()


Sequence of Method calls while saving the record in the Form
Form --- Datasource --- ValidateWrite ()
Table --- ValidateWrite ()
Form --- Datasource --- write ()
Table --- insert ()

Sequence of Methods calls while creating the record in the Form
Form --- Datasource --- create ()
Form --- Datasource --- initValue ()
Table --- initValue ()
Form --- Datasource --- active ()

Sequence of Methods calls while closing the Form
Form --- canClose ()
Form --- close ()


Sequence of Methods calls while modifying the fields in the Form
Table --- validateField ()
Table --- modifiedField ()

Sequence of Method calls while deleting the record in the Form
Form --- Datasource --- validatedelete ()
Table --- validatedelete ()
Table --- delete ()
Form --- Datasource --- active ()



17 October 2019

BOM Explode X++ logic in AX 2012 D365 FO

class BOMExplode
{
    date                        _date = mkDate(22,09,2019);
    void itemExplode(ItemId _ItemId, int _level = 0, BOMQty _bomQty = 1)
    {
        BOM                         bomTable;
        BOMVersion                  bomVersion;
        boolean                     enable;
        InventTestVariableId        cvQualityGroupId;
        Level                       level = _level;
       
        while select bomVersion
            where bomVersion.ItemId == _itemid
                && bomVersion.Active
                && bomVersion.FromDate <= _date//DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone())
                && (!bomVersion.ToDate || bomVersion.ToDate >= _date)//DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()))
        {
            if (bomVersion.RecId)
            {
                While select bomTable
                    where bomTable.BOMId == bomVersion.BOMId
                {
                    Info(strFmt("Parent Item: %1 Part Number: %2 Quantity: %3, Level: %4 ",bomVersion.ItemId,bomTable.ItemId, bomTable.bomQty,level));
                    if (this.hasChild(bomTable.ItemId))
                    {
                        this.itemExplode(bomTable.ItemId, level + 1, bomTable.BOMQty);
                    }
                }
            }
        }
    }

    boolean hasChild(ItemId _itemId)
    {
        BOMVersion  bomVersion;
        boolean     ret = false;

        select firstonly bomVersion
            where bomVersion.ItemId == _itemid
                && bomVersion.Active
                && bomVersion.FromDate <= _date//DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone())
        && (!bomVersion.ToDate || bomVersion.ToDate >= _date);//DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()));

        if (bomVersion.RecId)
        {
            ret = true ;
        }

        return ret;
    }

    public static void Main(Args args)
    {
        BOMExplode bomExplode = new BOMExplode();

        bomExplode.itemExplode("A20HBA06B7");

    }

}

04 September 2019

How to get AX applciation preiod start date and end date in D365 FO or ax7

PeriodStart             periodStartDate;
PeriodEnd               periodEndDate;

periodStartDate = FiscalCalendarYear::findYearByCalendarDate(Ledger::fiscalCalendar(), DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone())).StartDate;
        periodEndDate   = FiscalCalendarYear::findYearByCalendarDate(Ledger::fiscalCalendar(), DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone())).EndDate;

09 August 2019

How to explode BOM through X++ BOM Explode and subBOM X++ BOM versions and BOM

class BOMDesign
{
TmpBOMExplode tmpBOM;
}
private int InsertParentItem(ItemId _itemId, int _level)
{
InventTable inventTable;
;

//Gets the parent information and then insert on TmpBOMExplode Table with level 0.
select firstOnly inventTable where inventTable.ItemId == _itemId;

tmpBOM.ItemId = _itemId;
tmpBOM.ItemName = inventTable.itemName();
tmpBOM.Level = _level;
tmpBOM.BOMQty = 1 ;
tmpBOM.insert();

return _level+ 1 ;
}

boolean hasChild(ItemId _itemId)
{
BOMVersion bomVersion;
;

//Check if the item is also a BOM item.
select firstonly bomVersion
where bomVersion.ItemId == _itemid
&& bomVersion.Active
&& bomVersion.FromDate <= systemdateget () && (!bomVersion.ToDate || bomVersion.ToDate >= systemdateget ());

if (bomVersion.RecId)
return true ;

return false ;
}


void itemExplode(ItemId _ItemId, int _level = 0, BOMQty _bomQty = 1)
{
BOM bomTable;
InventTable inventTable;
BOMVersion bomVersion;
InventDim   inventDim;
;

//Insert parent Item
if (_level == 0)
_level = this.InsertParentItem(_ItemId, _level);

//Verifies if the Item exists in BOMVersion Table.
//The item must be active and not expired.
while select firstonly bomVersion
where bomVersion.ItemId == _itemid
&& bomVersion.Active
&& bomVersion.FromDate <= systemdateget() && (!bomVersion.ToDate || bomVersion.ToDate >= systemdateget());
// optoin comparing with Dimensions//
/*
exists join inventDim
            where inventDim.inventDimId == bomVersion.InventDimId &&
                  (inventDim.InventColorId == inventColorId || inventColorId == "") &&
                  (inventDim.InventSizeId == inventSizeId || inventSizeId == "");
*/
{
if (bomVersion.RecId)
{
//Every item on BOMVersion has a BOMId which is used to show
//which products belong to a BOM Item.
While select bomTable
where bomTable.BOMId == bomVersion.BOMId
join inventTable
where bomTable.ItemId == inventTable.ItemId
{
//Insert the items that compose the BOM Item with level 1.
tmpBOM.ItemId = bomTable.ItemId;
tmpBOM.ItemName = inventTable.itemName();
tmpBOM.RefItemId = bomVersion.ItemId;
tmpBOM.BOMQty = bomTable.BOMQty / bomTable.BOMQtySerie * _bomQty;
tmpBOM.Level = _level;
tmpBOM.insert();

//This method is used to check if the BOM Item is composed by
//another BOM Item, case true it will call the method recursively
// with level 2.
if (this.hasChild(bomTable.ItemId))
this.itemExplode(bomTable.ItemId, _level+ 1, tmpBOM.BOMQty);
}
}
}
public static void main(Args args)
{
BOMDesign bomDesign = new BOMDesign();
;

bomDesign.itemExplode( 'D0001', 0 );
}
}

For more info please click here for reference

Customer inbound custom service in D365 F&O with X++

  [DataContractAttribute] class GOD_CustomerCreateContract {     str                 accountNum;     // Optional; if blank, a number sequenc...