Thursday, 19 March 2015

how to open a URL from a job

infolog.urlLookup("your url").

if you create a new job and write this line 

infolog.urlLookup("http://rohitdynamics.blogspot.in/");


it will open respective web page.

Wednesday, 18 March 2015

Adding a image in a form

we can add a image in a form, what will happen is that it will open a form and it will display the image  in the form .

step1:go to the AOT right click on resource and select  create from file



select and image from the list



the save the file atlast in the resource section you will get something like

then create a form  and in a form design add a  control as window and set the auto declaration property as "Yes";



Then we have to write a method on the form

public void method1()
{
    container       imagedata;
    resourceNode   resourceNode;
    Image           Image;

    ResourceName    ResourceName =  resourceStr(Chrysanthemum_jpg);
    resourceNode  = SysResource::getResourceNode(ResourceName);
    if(resourceNode)
    {
        //load the image
        resourceNode.AOTload();
        imagedata = SysResource::getResourceNodeData(resourceNode);
        Image  = new Image();
        Image.setData(imagedata);

        //setting the image to window control
        //Window.
        CustomImage.image(Image);



    }

}

Once this method is written we need to call this  in the run method of the form.

public void run()
{
    super();
    element.method1();
}

When we wrote these method now our form is all set to go.

now right click on the form and open the form you will get a form something like this.



So this is one of the way to display image in a form in ax 2012 .





Wednesday, 4 March 2015

Job for deleting the Purchase Order from the Excel

static void Job39(Args _args)
{
    Dialog              _dialog;
    DialogField         _file;

    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    COMVariantType type;
   
    PurchTable       PurchTable;
    PurchLine        PurchLine;
    Name name;
    Filename filename;
    str journalName;
    str 50 POOrders;
   
    int row;
    ;

    row =1;
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    //specify the file path that you want to read
    //Prompt to import excel
    _dialog = new Dialog("Please select the file to load");
    _dialog.addText("Select file:");
    _file =_dialog.addField(extendedTypeStr(FilenameOpen));
    _dialog.run();
    if (_dialog.closedOK())
    {
        filename = _file.value();
        try
        {
            workbooks.open(filename);
        }
        catch (Exception::Error)
        {
            throw error("File cannot be opened.");
        }

        workbook = workbooks.item(1);
        worksheets = workbook.worksheets();
        worksheet = worksheets.itemFromNum(1); //Here 3 is the worksheet Number
        cells = worksheet.cells();
        do
        {
            row++;
            POOrders                     = cells.item(row, 1).value().bStr();
           
             ttsBegin;
     select  forUpdate PurchTable  where PurchTable.PurchId== POOrders;//"000013";
    {
       
        while select  forUpdate PurchLine  where PurchLine.PurchId == PurchTable.PurchId
        {
           
            PurchLine.doDelete();
        }
        PurchTable.doDelete();
       
    }
       ttsCommit;
           
            // Loads the next row into the variant type and validating that its is empty or not
            type = cells.item(row+1, 1).value().variantType();
        }
        while (type != COMVariantType::VT_EMPTY);
        application.quit();
    }



}

Tuesday, 3 March 2015

we can covert a string to a base enum also

Here say we have a base enum and we want to  assign a vaulue of the string to the base enum it can be done by   function "str2enum"



say we have a line od code :

 ledgerJournalTrans.AccountType = LedgerJournalACType::Bank;

it means AccountType 's value will be Bank

or else you can do this way also


  LedgerJournalACType   LedgerJournalACType;  //declare this variable in the top
ledgerJournalTrans.AccountType = str2enum(LedgerJournalACType,"Bank");

Container and unbounded string fields are not allowed in a WHERE expression.

Some time  when we give   a str variable in where condition it gives an error.


str Account;
;

select firstOnly bankAccountTable
                join RecId from ledgerDimension
                where ledgerDimension.DisplayValue      == bankAccountTable.AccountID
                //if(bankAccountTable.AccountID  == any2str(Account))
                &&    bankAccountTable.AccountID        == Account;

error message :Container and unbounded string fields are not allowed in a WHERE expression.


Str 50   Account1,Offset_account1;

 select firstOnly bankAccountTable
                join RecId from ledgerDimension
                where ledgerDimension.DisplayValue      == bankAccountTable.AccountID
                //if(bankAccountTable.AccountID  == any2str(Account))
                &&    bankAccountTable.AccountID        == Account1;

error gone and it will work perfectly.

Sunday, 1 March 2015

Create GL by X++

In order to create GL journal using X++ .

We need to populate following table
1.LedgerJournalTable
2.LedgerJournalTrans
3. LedgerJournalTransAccrual

LedgerJouranlTransAccrual table you can specify accrual start date and end date.

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();
        }
    }
}

intercompany PO multiple product receipt by x++

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