hljs.configure({cssSelector: "code"}); hljs.highlightAll();

Sunday, August 30, 2020

Query Classes in AX 2012

 static void queryClasses(Args _args)

{


    date            dateFrom    = 01\01\2012 ;

    date            dateTo      = 31\01\2012 ;

    Query query;

    QueryBuildDataSource queryBuildDataSource;

    QueryBuildRange queryBuildRange,qbr;

    QueryBuildFieldList  qbfl       ;

    QueryRun queryRun;

    CustTrans custTrans;

    ;

    query = new Query();

    queryBuildDataSource = query.addDataSource(tablenum(CustTrans));

    queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTrans,AccountNum));

    qbr = queryBuildDataSource.addRange(fieldNum(CustTrans,TransDate));

    //queryBuildRange.value("Us-010,us-020  ");

    qbr.value(SysQuery::range(dateFrom, dateTo));

    queryBuildDataSource.addSortField(fieldNum(CustTrans,AccountNum));

    //queryBuildDataSource.addSortField(fieldNum(CustTrans,Invoice));

    //Greater than or less than values passing

   // queryBuildRange.value('us-010..us-020');

    //passing like operator 

   // queryBuildRange.value('*Us*');

    //not like

    queryBuildRange.value('!*Us*');

    queryBuildDataSource.addSelectionField(fieldnum(CustTrans,RecId),SelectionField::Count);

    queryBuildDataSource.orderMode(OrderMode::GroupBy);

    info(queryBuildDataSource.toString());

    queryRun = new QueryRun(query);

    while (queryRun.next())

    {

    custTrans = queryRun.get(tablenum(CustTrans));


    info (strfmt(" Customer Account  :%1 Group : %2",custTrans.AccountNum,custTrans.RecId ));


    }

}

Friday, August 28, 2020

AOT Maps in Ax 2012

 The fields of the maps are basically use to map fields of one or more tables.By the help of a maps we can   access   the fields of one or more tables with different names.

Steps For Creating Maps:

  For implementation i have created two tables named DaxSalesTable and DaxProductsTable you can see  in          below  image.

                         

    in both the tables i have similar fields.

    After that i created a Map 

    AOT >> DataDictionary >> Maps and Right click and create a Map

    then add the fields to map here i have added three fields.As you can see in below image

                            

     

      Next,Under your newly created map you can find mappings node 

      Create mapping  and Set the property mapping table

            

   Here i have mapped DaxProductsTable  and then i have mapped the fields as you can see in below image

     

  Now I have created a job on which I will map a table on this map and than use it.

  static void Job3(Args _args)

{

    DaxMapTest          test; //map declaration

    // tables

    DaxSalesTable       daxSalesTable;

    DaxProductsTable    daxProductsTable;

    // Assigning values to the map 

    test.productnumber = "DAX-001";

    test.ProductName   = "Jaipal Jadav";

    info(strFmt("Map AccountNum : %1",test.productnumber));

    // Now here  setting accountnum field to daxProductsTable field

    test = daxProductsTable;

    test.productnumber = "DAX-002";

    test.ProductName   = "Srikanth Jadav";

    info(strFmt("Salestable AccountNum : %1",test.productnumber));

    //Now here  setting accountnum field to daxSalesTable field

    test = daxSalesTable;

    test.productnumber = "DAX-003";

    test.ProductName   = "Akhil Jadav";

    info(strFmt("Producttable AccountNum :%1",test.productnumber));

    

}

 Result:

  

           

Thursday, August 20, 2020

X++ Code to Create Purchase Order In Ax 2012

 Static void Purchaseorder()

{

PurchTable purchTable;

PurchLine purchline;

NumberSeq numberSeq;

InventDim InventDimloc;

numberSeq =NumberSeq::newGetNum(purchparameters::numRefPurchId(),true);

purchTable.initValue();

purchTable.PurchId = numberSeq.num();

purchTable.OrderAccount = "US-101";

purchTable.InvoiceAccount ="US-101" ;

purchTable.CurrencyCode = "USD";

purchTable.LanguageId = currentUserLanguage();

purchTable.initFromVendTable();

if (purchTable.validateWrite())

{

purchTable.insert();

}

//purchase order lines

purchLine.PurchId = purchTable.PurchId;

purchLine.ItemId = "D0001" ;

purchLine.itemIdChanged();

select InventDimId from inventDimLoc

where inventDimLoc.InventLocationId=="13"

&& inventDimLoc.InventSiteId=="1";

purchLine.InventDimId=inventDimLoc.InventDimId;

purchLine.PurchQty = 5.0;

purchLine.modifiedField(fieldNum(purchLine, PurchQty));

purchLine.PurchUnit = "EA";

//purchLine.PurchPrice = RealEdit1.realValue();

purchLine.modifiedField(fieldNum(purchLine, PurchPrice));

purchLine.setPriceDiscChangePolicy(PriceDiscSystemSource::ManualEntry,fieldNum(purchLine, PurchPrice));

purchLine.createLine(true, true, true, true, true, true);


ttsBegin;

purchLine.selectForUpdate(true);

// purchLine.InventDimId=inventDimLoc.InventDimId;

purchLine.PurchPrice = 500.0;

purchLine.LineAmount = purchLine.PurchQty * purchLine.PurchPrice ;

purchLine.update();

ttscommit;


info(strFmt("@DAR91",purchTable.PurchId));



}

Wednesday, August 19, 2020

General Journal Creation and Posting in AX 2012 Using X++

 static void GeneralJournalCreate(Args _args)

{

    //class for journal header creation

    AxLedgerJournalTable   axLedgerJournalTable ; 

    //class for journal lines creation

    AxLedgerJournalTrans   axLedgerJournalTrans;  

    container              accPattern;    

    container              offSetPattern;

    // class for journal  posting

    ledgerJournalCheckPost ledgerJournalCheckPost; 

    axLedgerJournalTable = new AxLedgerJournalTable();

    axLedgerJournalTrans = new AxLedgerJournalTrans();

    // Journal Header creation

    axLedgerJournalTable.parmJournalName("GenJrn");

    axLedgerJournalTable.save();     

    // Journal lines Creation

    axLedgerJournalTrans.parmJournalNum(axLedgerJournalTable.ledgerJournalTable().JournalNum);

    axLedgerJournalTrans.parmTransDate(systemDateGet());

    axLedgerJournalTrans.parmAmountCurDebit(300);

    //axLedgerJournalTrans.parmAmountCurcredit(300);

    axLedgerJournalTrans.parmAccountType(LedgerJournalACType::Ledger);

    // 2-indicates no of financial dimension values

    // 110110- main account id and dispaly name

    accPattern = ['110110','110110',2,'BusinessUnit',"001","Department","022"];

    axLedgerJournalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accPattern));

    offSetPattern = ['112140',"112140",2,'BusinessUnit','003',"Department","024"];

    axLedgerJournalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId( offSetPattern));

    axLedgerJournalTrans.save();

    info(strFmt("Journal %1 created", axLedgerJournalTable.ledgerJournalTable().JournalNum));

    // Journal Posting

    ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(axLedgerJournalTable.ledgerJournalTable(),NoYes::Yes);

    ledgerJournalCheckPost.run();

    info(strFmt("Journal No. %1.", axLedgerJournalTable.ledgerJournalTable().JournalNum));

}


  

Tuesday, August 18, 2020

Product and Product Master Release In AX 2012 Using X++

void lookup()

{

InventTable                                                    inventTable;

InventModelGroupItem                                 inventModelGroupItem;

InventItemGroupItem                                    inventItemGroupItem;

InventTableModule                                       inventTableModule;

InventItemSetupSupplyType                        inventItemSetupSupplyType;

EcoResStorageDimensionGroupItem          ecoResStorageDimensionGroupItem;

EcoResTrackingDimensionGroupItem        ecoResTrackingDimensionGroupItem;

EcoResStorageDimensionGroupProduct     ecoResStorageDimensionGroupProduct;

EcoResTrackingDimensionGroupProduct    ecoResTrackingDimensionGroupProduct;

//Release product or product master

inventTable.clear();

inventTable.initValue();

if (ecoResDistinctProduct.RecId)

{

inventTable.initFromEcoResProduct(ecoResDistinctProduct);

}

else if (ecoResProductMaster.RecId)

{

inventTable.initFromEcoResProduct(ecoResProductMaster);

}

inventTable.ItemId = ProductNumber.valueStr();

inventTable.NameAlias = Name.valueStr();

if (inventTable.validateWrite())

{

inventTable.insert();

//Inventory model group

inventModelGroupItem.clear();

inventModelGroupItem.initValue();

inventModelGroupItem.ItemDataAreaId = inventTable.dataAreaId;

inventModelGroupItem.ItemId = inventTable.ItemId;

//inventModelGroupItem.ModelGroupId = "FIFO";

inventModelGroupItem.ModelGroupDataAreaId = curext();

inventModelGroupItem.insert();

//Item group

inventItemGroupItem.clear();

inventItemGroupItem.initValue();

inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;

inventItemGroupItem.ItemId = inventTable.ItemId;

//inventItemGroupItem.ItemGroupId = "Parts";

inventItemGroupItem.ItemGroupDataAreaId = curext();

inventItemGroupItem.insert();

//Extended product details – Inventory

inventTableModule.clear();

inventTableModule.initValue();

inventTableModule.ItemId = inventTable.ItemId;

inventTableModule.ModuleType = ModuleInventPurchSales::Invent;

inventTableModule.insert();

//Extended product details – Purchase

inventTableModule.clear();

inventTableModule.initValue();

inventTableModule.ItemId = inventTable.ItemId;

inventTableModule.ModuleType = ModuleInventPurchSales::Purch;

inventTableModule.insert();

//Extended product details – Sales

inventTableModule.clear();

inventTableModule.initValue();

inventTableModule.ItemId = inventTable.ItemId;

inventTableModule.ModuleType = ModuleInventPurchSales::Sales;

inventTableModule.insert();

//Warehouse items

InventItemLocation::createDefault(inventTable.ItemId);

//Supply type setup

inventItemSetupSupplyType.clear();

inventItemSetupSupplyType.initValue();

inventItemSetupSupplyType.ItemId = inventTable.ItemId;

inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;

inventItemSetupSupplyType.insert();

//Product storage dimension group

ecoResStorageDimensionGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(ecoResDistinctProduct.RecId);

if (ecoResStorageDimensionGroupProduct.RecId)

{

ecoResStorageDimensionGroupItem.clear();

ecoResStorageDimensionGroupItem.initValue();

ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;

ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;

ecoResStorageDimensionGroupItem.StorageDimensionGroup = ecoResStorageDimensionGroupProduct.StorageDimensionGroup;

ecoResStorageDimensionGroupItem.insert();

}

//Product tracking dimension group

ecoResTrackingDimensionGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(ecoResDistinctProduct.RecId);

if (ecoResTrackingDimensionGroupProduct.RecId)

{

ecoResTrackingDimensionGroupItem.clear();

ecoResTrackingDimensionGroupItem.initValue();

ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;

ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;

ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;

ecoResTrackingDimensionGroupItem.insert();

}


}


Product and Product Master creation Using X++

void clicked()

{

EcoResProductTranslation ecoResProductTranslation;

EcoResDistinctProduct ecoResDistinctProduct;

EcoResProductIdentifier ecoResProductIdentifier;

EcoResProductMaster ecoResProductMaster;

EcoResProductDimensionGroupProduct ecoResProductDimensionGroupProduct;

//product creation

if(ecoResProductSubtype == EcoResProductSubtype::Product)

{

ecoResDistinctProduct.initValue();

ecoResDistinctProduct.DisplayProductNumber ="Dax123";

ecoResDistinctProduct.ProductType =EcoResProductType::Item;

ecoResDistinctProduct.SearchName ="Dax123";

ecoResDistinctProduct.doInsert();

ecoResProductTranslation.initValue();

ecoResProductTranslation.LanguageId =currentUserLanguage();

ecoResProductTranslation.Description ="Dax123";

ecoResProductTranslation.Name="Dax123";

ecoResProductTranslation.Product = ecoResDistinctProduct.RecId;

ecoResProductTranslation.doinsert();

if(ecoresdistinctproduct.recid)

{

ecoresproductidentifier.initValue();

ecoresproductidentifier.product=ecoresdistinctproduct.recid;

ecoresproductidentifier.productnumber=ecoResDistinctProduct.DisplayProductNumber;

ecoresproductidentifier.insert();

}

}

//product master creation

else

{

ecoResProductMaster.clear();

ecoResProductMaster.initValue();

ecoResProductMaster.ProductType = EcoResProductType::Item;

ecoResProductMaster.DisplayProductNumber = "Dax123";//ProductNumber.valueStr();

ecoResProductMaster.SearchName ="Dax123";// SearchName.valueStr();

ecoResProductMaster.VariantConfigurationTechnology = EcoResVariantConfigurationTechnologyType::PredefinedVariants;

if(ecoResProductMaster.validateWrite())

{

ecoResProductMaster.insert();

}

ecoResProductIdentifier.clear();

ecoResProductIdentifier.initValue();

ecoResProductIdentifier.ProductNumber = "Dax123";

ecoResProductIdentifier.Product = ecoResProductMaster.RecId;

ecoResProductIdentifier.insert();


ecoResProductDimensionGroupProduct.clear();

ecoResProductDimensionGroupProduct.initValue();

ecoResProductDimensionGroupProduct.initFromProduct(ecoResProductMaster);

ecoResProductDimensionGroupProduct.ProductDimensionGroup = EcoResProductDimensionGroup::findByDimensionGroupName('SizeColCon').RecId;

if(ecoResProductDimensionGroupProduct.validateWrite())

{

ecoResProductDimensionGroupProduct.insert();

}

EcoResProductTranslation::createOrUpdateTranslation(ecoResProductMaster.RecId, "Dax123";/*ProductNumber.valueStr()*\,"Dax123"; //SearchName.valueStr());

}

info('product created');

super();

}

RunBase And Runbase Batch In Ax 2012

RunBase class: 

Create a class CustomerRunbase Which extends from Runbase class. 


class CustomerRunbase extends RunBase 



    CustAccount custAccount; 


    DialogField custDldField; 


}  


Next create a Dialog method in class 


protected Object dialog() 



    DialogRunbase dialog; 


    dialog = super(); 


    dialog = super(); 


    custDldField = dialog.addFieldValue(extendedTypeStr(CustAccount),custAccount); 


    return dialog; 



Override Getfromthedialog method 


public boolean getFromDialog() 



    Query query = new Query(); 


    QueryBuildDataSource qbds; 


    QueryBuildRange qbr,Qbr1; 


    QueryRun qr; 


    SalesTable salesTable; 


    DAXCustDetails  DAXCustDetailsloc; 


    boolean ret; 


    ret = super(); 


    custAccount = custDldField.value(); 


    qbds=query.addDataSource(tableNum(SalesTable)); 


    qbr = qbds.addrange(fieldnum(SalesTable,CustAccount)); 


    qbr.value(custaccount); 


    qr = new QueryRun(query); 


    while (qr.next()) 


    { 


        salesTable = qr.get(tableNum(SalesTable)); 


        DAXCustDetailsloc.Customer = salesTable.CustAccount; 


        DAXCustDetailsloc.ItemId   = salesTable.SalesId; 


        DAXCustDetailsloc.insert(); 


    } 


    return ret; 



Create a Pack method 


public container pack() 



    return conNull(); 



Create a unpack method 


public boolean unpack(container packedClass) 



    return true; 



Lastly create a main method for class 


       public static void main(Args args) 



    CustomerRunbase runbase = new CustomerRunbase();


    if(runbase.prompt()) 


    { 


      runbase.run(); 


    } 


 


Try to run this you will get an dialog box with input parameter custaccount  like below image 

 

 

 

 

 

Select a customer “US-004” and press okay. 

You will get an info like this. 

 

Scenario is same as runbase class  


Create a class DaxCustomerRunbase which extends Runbasebatch class 


public class CustomerRunbasebatch extends RunBaseBatch 



    CustAccount         custAccount; 


    DialogField         custdialog; 



Create Dialog and getfromdialog methods 


protected Object dialog() 



    DialogRunbase dialog; 


   dialog = super(); 


    dialog = super(); 


    custdialog = dialog.addFieldValue(extendedTypeStr(CustAccount),custAccount); 


    return dialog; 



public boolean getFromDialog() 



    Query query = new Query(); 


    QueryBuildDataSource qbds; 


    QueryBuildRange qbr,Qbr1; 


    QueryRun qr; 


    SalesTable salesTable; 


    DAXCustDetails  DAXCustDetailsloc; 


    boolean ret; 


    ret = super(); 


    custAccount = custdialog.value(); 


    qbds=query.addDataSource(tableNum(SalesTable)); 


    qbr = qbds.addrange(fieldnum(SalesTable,CustAccount)); 


    qbr.value(custaccount); 


    qr = new QueryRun(query); 


    while (qr.next()) 


    { 


        salesTable = qr.get(tableNum(SalesTable)); 


        DAXCustDetailsloc.Customer = salesTable.CustAccount; 


        DAXCustDetailsloc.ItemId   = salesTable.SalesId; 


        DAXCustDetailsloc.insert(); 


    } 


        return ret; 



Create pack and unpack methods as you created in runbase class 


Create a main method 


public static void main(Args args) 



    CustomerRunbasebatch runbase = new CustomerRunbasebatch(); 


    if(runbase.prompt()) 


    { 


      runbase.run(); 


    } 



You can also create few more methods based on your requirement  . 


Methods: 


      CanGoBatch, canGoBatchJournal, initParmDefault,Validate. 


  


Run the class the dialog box opens 


As you can see here Batch Tab highlighted in below image while runbase class we cant find this tab 

 

 

 

  • Press okay and check the result