Thursday, January 21, 2016

commissions Setup and calculation

https://technet.microsoft.com/en-us/library/aa497145.aspx
http://axtradeandlogistics.blogspot.com/2015/03/commissions-setup-and-calculations-in.html

Number Sequence Creation through Code X++

//Number Sequence Creation through Code X++

static void Fcc_NumberSeqTest(Args _args)
{
     NumberSequenceTable                numberSeqTable;
     NumberSequenceScope                numberSeqScope;
     container                          segments;
     str                                annotatedFormat, format;
     NumberSequence                     sequence;
     Args                               args = new Args();
     ;
     select  numberSeqScope
           where numberSeqScope.DataArea == 'dataAreaId';
     segments += [[0, 'CVT']];
     segments += [[-1,'-']];
     segments += [[-2,'######']];
     annotatedFormat  = NumberSeq::createAnnotatedFormatFromSegments(segments);
     format           = NumberSeq::createAnnotatedFormatFromSegments(segments, false);
     numberSeqTable.clear();
     numberSeqTable.NumberSequence      = 'CVTst';
     numberSeqTable.Txt                 = 'Test Seq';
     numberSeqTable.AnnotatedFormat     = annotatedFormat;
     numberSeqTable.NumberSequenceScope = numberSeqScope.RecId;
     numberSeqTable.Format              = format;
     numberSeqTable.Highest             = 999999;
     numberSeqTable.Lowest              = 1;
     numberSeqTable.NextRec             = 1;
     numberSeqTable.insert();  
   
     args.record(NumberSequenceTable::find(numberSeqTable.RecId));
     new MenuFunction(MenuItemDisplayStr(NumberSequenceDetails),MenuItemType::Display).run(args);
}

Collection Class Ax 2012

Collection Class Ax 2012
https://msdn.microsoft.com/en-us/library/aa608508.aspx
http://www.junctionsolutions.com/dynamicsax/using-dynamics-ax-collection-classes-3/

source:
http://axgenius.blogspot.com/2016/03/collection-classes-in-ax-2012.html

Source blog information:

Collection Classes
We cannot store objects in arrays (x++ class) or containers. The Microsoft Dynamics AX collection classes have been designed for storing objects. 
Below are collection classes: Set , Map , List , Array (Collection class)
A Set is used for the storage and retrieval of data from a collection in which the members are unique. The values of the members serve as the key according to which the data is automatically ordered. Thus, it differs from a List collection class where the members are placed into a specific position, and not ordered Automatically by their value.
static void Set(Args _args)
{
    Set setOne;
    Set setTwo;
    SetEnumerator enumerator;
    Int value;
    setOne = new Set(types::Integer);
    setOne.add(4);
    setOne.add(6);
    setOne.add(3);
  
    enumerator = setOne.getEnumerator();
    while (enumerator.moveNext())
    {
        value = enumerator.current();
        info(strFmt("%1",value));     
    }
}
Output :- 3
                 4
                 6
A List object contains members that are accessed sequentially. Lists are structures that can contain members of any X++ type. All the members in the same list must be of the same type.
static void List(Args _args)
{
    List integerList = new List(Types::Integer);
    ListEnumerator enumerator;
    // Add some elements to the list
    integerList.addEnd(1);
    integerList.addEnd(4);
    integerList.addEnd(3);
    // Set the enumerator
    enumerator = integerList.getEnumerator();
    // Go to beginning of enumerator
    enumerator.reset();
    //Go to the first element in the List
    while(enumerator.moveNext())
    {
        info(strfmt("%1", enumerator.current()));
    }
}
Output :- 1
                 4
                 3
A Map object associates one value (the key) with another value. Both the key and value can be of any valid X++ type, including objects. The types of the key and value are specified in the declaration of the map. The way in which maps are implemented means that access to the values is very fast.
static void Map(Args _args)
{
    Map mapTest;
    MapEnumerator enumerator;
 
    mapTest = new Map(Types::String, Types::Integer);
  
    mapTest.insert("One", 1);
    mapTest.insert("Two", 2);
  
    enumerator = mapTest.getEnumerator();
    while (enumerator.moveNext())
    {
        info(strfmt("Key - %1 , Value  - %2.",enumerator.currentKey(),enumerator.currentValue()));
    }
}
Output:- Key - One , Value  - 1.
                Key - Two , Value  - 2.

Array inserts, sometimes referred to as bulk inserts, are implemented in the kernel. They buffer a group of rows and insert them in a single trip to the SQL backend. This vastly reduces the number of trips, and speeds up inserts. You can use RecordSortedList or RecordInsertList to hold your rows until they are inserted. Both classes have an insertDatabase method that is used to insert the records into the database as efficiently as possible. However, the insertDatabase method does
RecordSortedList
                     
                         Use RecordSortedList when you want a subset of data from a particular table, and you want it sorted in an order that does not currently exist as an index.
A RecordSortedList object holds records from a single table. The list has a unique key that is defined by the fields listed by using the sortOrder method.
Records are automatically sorted as they are inserted, they do not have to be inserted in sort sequence.
There is no limit to the size of a RecordSortedList object, but they are completely memory-based, so there are potential memory consumption problems.
RecordSortedList objects must be server-located before the insertDatabase method can be called. Otherwise, an exception is thrown.
Record level security (RLS) cannot be applied by the RecordSortedList class. RLS is applied by the RecordInsertList class).
Compared to temporary tables, RecordSortedList objects:
are faster
are not disk-based
only have one index
cannot be used in forms
require a call between the client and server per (grouped) read
 Ex:
Student student;
RecordSortedList recordSortedList = new RecordSortedList(tablenum(Student));
recordSortedList .sortOrder(fieldname2id(tablenum(Student),’StudentId’));
student.clear();
student.StudentID=”123?;
student.FirstName=”DOM”;
student.LastName=”FED”;
recordSortedList.ins(student);
student.clear();
student.StudentID=”456?;
student.FirstName=”TOM”;
student.LastName=”GED”;
recordSortedList.ins(student);
 student.clear();
student.StudentID=”789?;
student.FirstName=”ROM”;
student.LastName=”TED”;
recordSortedList.ins(student);
recordSortedList.insertDatabase();
RecordInsertList:
               The RecordInsertList class provides array insert capabilities in the kernel. This allows you to insert more than one record into the database at a time, which reduces communication between the application and the database.
               The array insert operation automatically falls back to classic record-by-record inserts when non-SQL based tables are used (for example, temporary tables), or when the insert method on the table is overridden (unless it is explicitly discarded).
Ex:
FiscalCalendar myTable;
 RecordInsertList insertList = new RecordInsertList(myTable.TableId, True);
  int i;
 for ( i = 1; i <=  100; i++ )
 {
        myTable.CalendarId = "F"+int2str(i);
        insertList.add(myTable);
 }
 insertList.insertDatabase();

Thursday, September 3, 2015

EcoResCategory Category Lookup in Form

// EcoResCategory Lookup in Form

Enable Purch/Sales Category in Customized Table:

TableOne(Customize Table)
1)      Create New Field – Data Type (Int64) ,Extends to Purch Category/Sales Category
2)      Create New Relation for New Field
2.1) Relation Table – EcoResCategory
2.2) Create Normal Relation
        Field – TableOne.fieldName == EcoResCategory.RecId
2.3) Relation Properties Changes to
      2.3.1) RelatedTableCardinality – ZeroOne
       2.3.2) Cardinality – Zero More
       2.3.3) RelationShip Type – Association
     à Form
3)      Form à datasource à tableàField(category Field)
3.1) Add New Method  -- resolveReference
 public Common resolveReference(FormReferenceControl _formReferenceControl)
{
    return EcoResCategory::resolveCategoryHierarchyRole(
        _formReferenceControl,
        EcoResCategoryNamedHierarchyRole::(CategoryType));
}

3.2) Add New Method  -- lookupReference

public Common lookupReference(FormReferenceControl _formReferenceControl)
{

        return EcoResCategory::lookupCategoryHierarchyRole(
            _formReferenceControl,
            EcoResCategoryNamedHierarchyRole:: ::(CategoryType));
}

3.3) Add New Method  -- Modified

public void modified()
{
    <CategoryEDT>               NAmeCategory;
    ItemFreeTxt                 name;
    LedgerDimensionAccount      ledgerDimension;

    name                     = salesQuotationLine.Name;

    NAmeCategory = salesQuotationLine.fieldName;
    salesQuotationTableForm.resetSalesQuotationLine(salesQuotationLine);
    salesQuotationLine. fieldName = NAmeCategory;
    salesQuotationLine_ds.changedInventoriedStatus();
 }



Tuesday, August 18, 2015

Inventory Item Registration lines Auto in ax 2012

//Inventory Item Registration in Transfer Order lines Auto in ax 2012
//Registering an Item , success only when On hand Avail physical Qty is greater than Zero

static void San_InvTransRegistrationCode(Args _args)
{
    InventTransferTable     transferTable;
    InventTransferLine      transferLine;
    InventTransWMS_Register inventTransWMS_register;
    InventTrans             inventTrans;
    TmpInventTransWMS       tmpInventTransWMS;
    InventDim               inventDim,Dimtmp,inventDimCreate;
    int                     i;
    Name                    size,color,warehouse,wmslocation,site;

    while select transferTable
                where transferTable.InventLocationIdFrom == "<from warehouse number>"   && transferTable.InventLocationIdTo == "<To Warehouse number>"
                            && transferTable.TransferStatus == InventTransferStatus::Shipped
                            //&& transferTable.TransferId =="<Transfer Order id>"
    {
        while select transferLine where transferLine.TransferId == transferTable.TransferId
               //&&  transferLine.ItemId == "<Item number >"
        {
            Dimtmp.clear();
            Dimtmp.InventSizeId = InventDim::find(transferLine.inventDimId).InventSizeId;
            Dimtmp.InventColorId = InventDim::find(transferLine.inventDimId).InventColorId;
            Dimtmp.InventLocationId = transferTable.InventLocationIdTo;
            Dimtmp.wMSLocationId = "Default";
            Dimtmp.InventSiteId = InventDim::find(transferLine.inventDimId).InventSiteId;
            inventDimCreate = inventDim::findOrCreate(Dimtmp);

            ttsBegin;
            inventTrans = InventTrans::findTransId(transferLine.InventTransIdReceive,true);
            if(inventTrans)
            {
                inventTrans.inventDimId = inventDimCreate.InventDimId;
                inventTrans.update();
            }
            ttsCommit;

            inventDim = inventDim::find(inventTrans.inventDimId);
            inventTransWMS_register = inventTransWMS_register::newStandard(tmpInventTransWMS);
            tmpInventTransWMS.clear();
            tmpInventTransWMS.initFromInventTrans(inventTrans);
            tmpInventTransWMS.InventQty = transferLine.QtyShipped;
            tmpInventTransWMS.InventDimId = inventTrans.InventDimId;          
            tmpInventTransWMS.insert();

            inventTransWMS_register.writeTmpInventTransWMS(tmpInventTransWMS,inventTrans,inventTrans.inventDim());
            inventTransWMS_register.updateInvent(transferLine);
  i++;
        }
    }
}

Sunday, August 2, 2015

Hiding form parts in a form

Please use this Code if you want to hide a few parts(Form Parts or Info Parts) in your form

Form --> method --> Run

 PartList        partList;
 int                partListCount,cnt;
 FormRun     factBox;

        partList = new PartList(element);
        cnt = partList.partCount();

        for (partListCount = 1; partListCount <= cnt; partListCount++)
        {
            factBox = partList.getPartById(partListCount);
            switch(factBox.name())
            {
                // Header factboxes:
                case identifierStr(InventOnHandItemCostPart):
                    factBox.design().visible(false);
                    break;
            }
       }

Saturday, July 25, 2015

Enable filter option in Display method Ax 2012

/// To Enable filter option in Display method Ax 2012


public void context()
{
    int             selectedMenu;
    formrun         fr;
    Args            ag;
    Name            strtext;
    querybuilddataSource qb1;
    queryrun    qr;
    query       q;
    PopupMenu menu = new PopupMenu(element.hWnd());
    int a = menu.insertItem('Filter By Field');
    int b = menu.insertItem('Filter By Selection');
    int c = menu.insertItem('Remove Filter');
    ;

    selectedMenu = menu.draw();
    switch (selectedMenu)
    {
    case -1:
            break;
    case a:
            ag = new args('SysformSearch');
            fr = new formrun(ag);
            fr.run();
            fr.wait();
            strtext = fr.design().controlName('FindEdit').valueStr();
            if(strtext)
            {
                q   = TestDisplayLkp_ds.query();
                qb1 = q.dataSourceTable(tablenum(TestDisplayLkp));
                qb1 = qb1.addDataSource(TableNum(InventTable));
                qb1.addLink(FieldNum(TestDisplayLkp,ItemId1),FieldNum(InventTable,ItemId));
                qb1.addRange(FieldNum(InventTable,NameAlias)).value(strtext);
                TestDisplayLkp_ds.query(Q);
                TestDisplayLkp_ds.executeQuery();
            }
            break;

    case b:
            q   = TestDisplayLkp_ds.query();
            qb1 = q.dataSourceTable(tablenum(TestDisplayLkp));
            qb1 = qb1.addDataSource(TableNum(InventTable));
            qb1.addLink(FieldNum(TestDisplayLkp,ItemId1),FieldNum(InventTable,ItemId));
            qb1.addRange(FieldNum(InventTable,NameAlias)).value(strtext);
            TestDisplayLkp_ds.query(Q);
            TestDisplayLkp_ds.executeQuery();
            break;
    case c :
            q   = new Query();
            qb1 = q.addDataSource(tablenum(TestDisplayLkp));
            qb1.clearLinks();
            qb1.clearRanges();
            TestDisplayLkp_ds.query(Q);
            TestDisplayLkp_ds.removeFilter();
            break;

    Default:
            break;
    }

}

Monday, July 20, 2015

Retail AX

Retail Blogs:

http://axretail.blogspot.ae/

http://ax-retail.com/ 

Entity Relationship Diagram in Ax 2012 ( New Creation and Existing ER)

ER Diagram for System Default Table in Ax 2012 for all Modules

https://www.microsoft.com/dynamics/ax/erd/ax2012r2/

And We can also create new ER diagram for our Customize Table (New Functionality) also by using Below Link tutorial

https://www.visual-paradigm.com/tutorials/reverse-ddl.jsp
.bak
.sql

.sql and .bak file to Reverse ddl to make ER in SQL server 2012

Wednesday, July 15, 2015

Inventory Marking Functionality x++ Batch in Ax 2012

// Inventory Marking Functionality in X++ for All Transaction:

 Create New Batch Class , Extends RunBaseBatch

public void InventAutoMarkingRec()
{
    //InventTransOrigin InventTransOrigin,InventTransOriginL;
    InventTrans InventTrans,InventTransL;
    InventTransOriginId receiptInventTransOriginId;
    CostAmountValue CostAmountValue1,CostAmountValue2;

   while select forupdate InventTransOrigin
                    where InventTransOrigin.ReferenceId == ‘Reference Id’
            join InventTrans where InventTransOrigin.RecId == InventTrans.InventTransOrigin
                     && InventTransOrigin.ReferenceCategory == inventtranstype::InventTransaction
                            && InventTrans.StatusReceipt ==StatusReceipt::Purchased
                                //&& (InventTransOrigin.itemid == '9696'||InventTransOrigin.itemid == '9697')
    {
        //qtyToMark = InventTrans.Qty;
       // inventDim        = InventTrans.inventDim();
      while  select forupdate InventTransOriginL
                                where InventTransOriginL.ReferenceId == ‘Reference Id’

                    join InventTransL where InventTransOriginL.RecId == InventTransL.InventTransOrigin
                                && InventTransOriginL.ReferenceCategory == inventtranstype::InventTransaction
                                    && InventTransL.StatusIssue == StatusIssue::Sold
                                        && InventTransL.Qty * -1 == InventTrans.Qty
                                            // && InventTransOrigin.itemid ==InventTransOriginL.itemid
                                            //&& InventTrans.CostAmountPosted == InventTransL.CostAmountPosted *-1
                                            //&& InventTransOrigin.itemid =='1004'
            {
                CostAmountValue1=  InventTrans.CostAmountPosted;
                CostAmountValue2=  InventTransL.CostAmountPosted * -1;
                if(CostAmountValue1 == CostAmountValue2)
                {

                    this.AdremTek_San_InvMarkAuto(InventTransOriginL.InventTransId,InventTransOrigin.InventTransId,InventTrans.Qty);
                    info(strFmt("%1 -Lot Id %2 - Ref Lot %3",InventTransOrigin.ItemId,InventTransOriginL.InventTransId,InventTransOrigin.InventTransId));
                }
            }
     }
}


void Adt_San_InvMarkAuto(InventTransId _issueInventTransId,InventTransId _receiveInventTransId,InventQty _qty)
{
    InventTrans issueInventTrans;
    TmpInventTransMark tmpInventTransMask;
    Map mapMarkNow;
    container con;
    real qty;
    Map mapTmp;
    MapEnumerator mapEnumerator;

    //for Issue Lot Id
    InventTransOriginId issueInventTransOriginId =
        InventTransOrigin::findByInventTransId(_issueInventTransId).RecId;
    //For ReceiptL  Lot Id
    InventTransOriginId receiptInventTransOriginId =
        InventTransOrigin::findByInventTransId(_receiveInventTransId).RecId;
    InventQty qtyToMark = _qty; // Qty Need to Mark

    ttsBegin;

    issueInventTrans = InventTrans::findByInventTransOrigin(issueInventTransOriginId);

    [con, qty] = TmpInventTransMark::packTmpMark(InventTransOrigin::find(issueInventTransOriginId),issueInventTrans.inventDim(),issueInventTrans.Qty);

    mapTmp = Map::create(con);
    mapEnumerator = mapTmp.getEnumerator();
    while (mapEnumerator.moveNext())
    {
        tmpInventTransMask = mapEnumerator.currentValue();

        if (tmpInventTransMask.InventTransOrigin == receiptInventTransOriginId)
        {
            tmpInventTransMask.QtyMarkNow = qtyToMark;
            tmpInventTransMask.QtyRemain -= tmpInventTransMask.QtyMarkNow;
            mapMarkNow = new Map(Types::Int64, Types::Record);
            mapMarkNow.insert(tmpInventTransMask.RecId, tmpInventTransMask);

            TmpInventTransMark::updateTmpMark(
                issueInventTransOriginId,
                issueInventTrans.inventDim(),
                -qtyToMark,
                mapMarkNow.pack());

            break;
        }
    }

    ttsCommit;
}


Export label custom content

 GRID => Properties "Export Label" => "SalesReportMexico" To get download file with custom naming.