Sunday 22 February 2015

Ax 3.0 technical document

Please find  the technical document for AX 3.0  here

https://drive.google.com/file/d/0Bxop-xJu8BIyM0NGZ080MDFtT1E/view

AX 2009 POS book

https://drive.google.com/file/d/0Bxop-xJu8BIyR0tEU1YzUnI5QVk/view?usp=sharing

Tuesday 10 February 2015

job to create a quality order

static void Job32(Args _args)
{

   InventQualityOrderTable      InventQualityOrderTable;
   NumberSeq                    NumberSeq;
   InventQualityOrderId         QualityOrderId;
   InventDim                    InventDim;

   try
    {



    NumberSeq=NumberSeq::newGetNum(InventParameters::numRefQualityOrderId());
    NumberSeq.used();
    QualityOrderId = NumberSeq.num();
    ttsBegin;
   
     InventDim.initValue();

    InventDim.InventSiteId = "3";
    InventDim.InventLocationId = "31";
    InventDim = InventDim::findOrCreate(InventDim);
    InventDim.insert();

    InventQualityOrderTable.initValue();
    InventQualityOrderTable.ReferenceType = InventTestReferenceType::Inventory;
    InventQualityOrderTable.QualityOrderId = QualityOrderId;
    InventQualityOrderTable.ItemId        = "M0061";
    InventQualityOrderTable.TestGroupId   = "Concentrat";
    InventQualityOrderTable.Qty           = 0.002;
    InventQualityOrderTable.InventDimId   = "AN41-001116";
    InventQualityOrderTable.insert();
   //  select InventDim  where InventDim.inventDimId == InventQualityOrderTable.InventDimId;
 
    InventDim.insert();
    ttsCommit;

    if(InventQualityOrderTable.Qty)
    {
        info("Quality order created");
    }
       
    }
   
  catch
    {
        checkFailed("error");
       
       
       
    }

}

Coloring the grid in the form grid in AX 2012 based on the condition

Say We have a requirement in the form that all the boys should be marked as green color and rest every thing should be  plain(no color)

First we create a table where we put a field which is sex and this sex is a base enum will contain 3 values like none,male and female.


then create a form with the respective datasource  and design a grid and put all the fields over there


then write the code  by overwriting the datasource
public void displayOption(Common _record, FormRowDisplayOption _options
{

    Aaaaa   Aaaaaloc = _record;

   if(Aaaaaloc.sex == ABC::male)
    {
        _options.backColor(WinApi::RGB2int(50,255,50)); //Green
    }


    super(_record, _options);
}

see the out put as :



Monday 9 February 2015

difference between main and run method in ax 2012 class

Main is the entry point of a class, you can use it as a constructor method of your class, depending on the argument you can instantiate a new child class and return it's object. 


Run is used to write the code to process the business logic for that class
In addition to that, Main is recognized by kernel and is executed when you call that class from the Menu item. On the other hand, Run is just a user defined method that by design should be used to execute the main job of the class.

  1. Create a X++ job in the Jobs AOT node. Place code that invokes your class in the job body and press F5 to run.
  2. Create a main method on your class with the following signature:

static void main (Args _args) 
    // Your X++ code here. 
}

main method of a class in AX 2012

public static void main(Args args)
{
    DirNameSequenceUpdate nameSequenceUpdate;
    DirNameSequence nameSequence;

    // Find name sequence
    if(args.record() && args.record().TableId == tablenum(DirNameSequence))
    {
        nameSequence = args.record();

        // Run batch
        nameSequenceUpdate = new DirNameSequenceUpdate();
        nameSequenceUpdate.parmnameSequenceRecId(nameSequence.RecId);
        if (nameSequenceUpdate.prompt())
        {
            nameSequenceUpdate.run();
        }
    }
}

Sunday 8 February 2015

create a customer and its address via job in ax 2009


code for urbanbuzz

static void CustCreate_AX2009(Args _args)
{

        CustTable                           CustTable,CustTableLoc,CustTableLoc2;
        DirpartyTable                       DirpartyTable;
        DirPersonPartyDetail                DirPersonPartyDetail;
        DirPartyAddressRelationship         DirPartyAddressRelationship;
        Address                             Address;
        DirPartyAddressRelationshipMapping  DirPartyAddressRelationshipMapping;
        ;
        select CustTableLoc2  where  CustTableLoc2.Phone== "9600147034145" || CustTableLoc2.Email == "rohitsinghbatchu1@hotmail.com";
           if(CustTableLoc2)
            {
                throw error("duplicate phone number or Email Please create a new account");
            }
           else
           {
                CustTable.initValue();
                CustTable.AccountNum ="Mcafee10000023";
                CustTable.CustGroup = "Test";
                CustTable.Name ="ROhit Singh";
                CustTable.PartyType = DirPartyType::Person;
                CustTable.Phone = "9600147034145";
                CustTable.Email = "rohitsinghbatchu1@hotmail.com";
                CustTable.LanguageId = "en-us";
                    if(CustTable.validateWrite())
                    {
                         CustTable.insert();
                    }

                info(strfmt("%1",CustTable.AccountNum));
                CustTable.Street = 'Knowledge Village';
                CustTable.City = 'dubai';
                CustTable.CountryRegionId = 'UAE';
                CustTable.ZipCode = '502964';
               dirparty::updatePartyFromCommonInsert(CustTable.PartyId, CustTable);
    }
        select  DirpartyTable
        where DirpartyTable.PartyId ==CustTable.PartyId;

        select DirPersonPartyDetail
        where  DirPersonPartyDetail.PartyId == DirpartyTable.PartyId;
                if(DirPersonPartyDetail)
                {
                        info(strfmt("%1",DirPersonPartyDetail.AnniversaryDate));
                }
                 else
                 {
                        DirPersonPartyDetail.initValue();
                        DirPersonPartyDetail.BirthDate = 12\12\1984;
                        DirPersonPartyDetail.PartyId = CustTable.PartyId;
                        DirPersonPartyDetail.Gender = Gender::Male;
                        DirPersonPartyDetail.insert();
                  }
        ttsbegin;
        select forupdate CustTableLoc  where CustTableLoc.AccountNum == CustTable.AccountNum;
        CustTableLoc.LanguageId = "en-us";
        CustTableLoc.Name = "Rohit Singh";
        CustTableLoc.update();
        ttscommit;
}

Thursday 5 February 2015

how to update and insert the table in ax 2012

very often we do update and insert in tables using select and while select,In ax first thing to know is the diffrence between select and while select.

Say we are going to update a existing record:

rule No1: select that particular record
rule no2: use ttsbegin and commit
rule no3:assign the value and do "update"  or "doupdate";
*******************
 static void Job31(Args _args)
{
    LedgerJournalTable  LedgerJournalTable;
    ;
   select  forUpdate LedgerJournalTable  where LedgerJournalTable.JournalName =="ttt";
   ttsbegin;
    LedgerJournalTable.JournalNum = '1478.45';
    LedgerJournalTable.AssetTransferType_LT = LtAssetTransferType::TransferJour;
    LedgerJournalTable.update();
   ttscommit;
}
*************************************

say we are inserting a new value in a table
follow this rule
1.intialise the table.
2.assign the vaulue to the table's field
3.write the insert or doinsert method.

static void Job31(Args _args)
{
    LedgerJournalTable  LedgerJournalTable;
    ;
    LedgerJournalTable.initValue();
 
   
 
    LedgerJournalTable.JournalName = "ttt";
    LedgerJournalTable.JournalNum = '4578.124';
    LedgerJournalTable.AssetTransferType_LT = LtAssetTransferType::TransferJour;
    LedgerJournalTable.insert();
    if(LedgerJournalTable.validateWrite())
    {
    LedgerJournalTable.insert();
    }
   
 
}


Monday 2 February 2015

tables related to a particular module

static void tablesinamodule(Args _args)
{
// The name of the configuration key to be specified here
    str                     configKeyName   = "ProdShop";
    Dictionary              dictionary      = new Dictionary();
    ConfigurationKeyId      configKeyId     = dictionary.configurationKeyName2Id(configKeyName);
    TableId                 tableId;
    DictConfigurationKey    dictConfigurationKey;
    DictTable               dictTable;
    container               keyIds;
    int                     i;
    ;

    if (configKeyId)
    {
        // Find all children of the specified configuration key
        for (i = dictionary.configurationKeyNext(0); i; i = dictionary.configurationKeyNext(i))
        {
            dictConfigurationKey = new DictConfigurationKey(i);

            while (dictConfigurationKey.parentConfigurationKeyId())
                dictConfigurationKey = new DictConfigurationKey(dictConfigurationKey.parentConfigurationKeyId());

            if (dictConfigurationKey.id() == configKeyId)
                keyIds += i;
        }

        // Find all tables that have an appropriate configuration key
        i = 0;
        for (tableId = dictionary.tableNext(0);tableId;tableId = dictionary.tableNext(tableId))
        {
            dictTable = new DictTable(tableId);
            if (!dictTable.isMap() && !dictTable.isTmp() && !dictTable.isView())
            {
                if (confind(keyIds, dictTable.configurationKeyId()))
                {
                    i++;
                    info(dictTable.name());
                }
            }
        }
    }

    info(strfmt("%1 tables have configuration key '%2'", i, configKeyName));
}

intercompany PO multiple product receipt by x++

public void processStampICPO(PackingSlipId _deliveryNote,                             Transdate _deliverydate,                             ...