Sunday 22 March 2015

pass value from form to class in AX 2012

here we want to pass the value from the form to class.



if (args.caller() && formHasMethod(args.caller(), identifierstr(M)))
 {
        formRunObject = args.caller();
        formRunObject.M();    
}

this code does not work in ax 2012 but it works fine in ax 2009.

 here  we have to create a class , a menu item as action   and then call this menu item in form's click method and then pass the value in the class through menu item and  catch the vaulue in the main method of class.

First create a form  demo form with a table called demo table where we will have only one field over there   and one grid in design and one button over there.



then create a class1


create a menu item with action type and assign the class to that.



then write the click method of that button as 

void clicked()
{
    //super();

    MenuFunction    mf;
    args            args = new Args();
    ;


    args.record(DemoTable);


    mf = new menufunction(identifierstr(MenuItem1), MenuItemType::Action);
    mf.run(args);
}

now open the form and insert a record and click the button you will get output as 


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.

intercompany PO multiple product receipt by x++

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