Thursday 19 January 2012

How to filter records in the form by code in Ax 2009

Hi friends we are going to filter the records in the form by using the code in Ax 2009
Step 1: Declare a class variable
In the ClassDeclaration method of the form, define a range.

QueryBuildRange CurrencyQBR;

Step 2: Instantiate the new range.
In the init method on the datasource of the form, you assign the range to a specific field (after the super call).

public void init()
{
super();

CurrencyQBR = this.query().dataSourceName('CustTable').addRange(fieldnum(CustTable,Currency));
}

Step 3: In the last step, you assign a value to the range.
This is done in the executeQuery method on the same datasource of the form. Before the super call. Like this:

public void executeQuery()
{ ;

CurrencyQBR.value(queryvalue('USD'));

super();
}

    By this you can filter record
                                                     Vivek Chirumamilla

Wednesday 18 January 2012

Create a parameter Table in Ax 2009

Hi Friends,
    We have a small requirement of making a parameter Table to separate module. The basic of parameter table is found in this blog. We have a mandatory field named "key" which is of integer type.The properties of parameter table is as follows,
MaxAccessMode   Edit
CacheLookUP       Found
TableGroup           Parameter
And the properties of Key field is as follows
AllowEditOnCreate,AllowEdit, Visible is set to "NO"
The methods of find and exist are as follows,

static client server FleetParameters  find(boolean _forupdate = false)
{
    Parameters parameter;
    ;
        select firstonly parameter
            index Key
            where parameter.Key == 0;

        if (!parameter)
        {
            Company::createParameter(parameter);
            NumberSeqReference::construct(Parameters::numberSeqModule()).load();
        }
    return parameter;
}

exist

static boolean exist()
{
    return (select firstonly RecId from Parameters).RecId != 0;
}
And the update method of Table

void update()
{
    super();
    flush Parameters;
}
And Delete method of Table is overriden as

void delete()
{
    throw error("@SYS23721");
}
And a method called number sequence module is written as

static client server NumberSeqModule  numberSeqModule()
{
    return NumberSeqReference_VkFleet::numberSeqModule();
}

And then create a form parameters
And do not forget to write the init method on the form , The form data source properties is as follows
AllowCheck,AllowDelete,AllowCreate is set to "No",LinkType  "Passive",Insert at end  "No".

                                                                              Vivek Chirumamilla







Monday 16 January 2012

Writing a display method in Ax 2009

Hi friend we are going  learn about the display method in Ax 2009 . We have a table say Table1. We have to display a field say Field value in Table1,which is coming from field2 from Table2.Say we have a common field called Cfield ,based on the value of Cfield the value of field we have to display field2 value in Table1.
Create a new method on Table1 write the code below,

// display method()
display Field2 field2()
{
    return this.Table2(this.Cfield).field2;
}
create a new method in Table1 and write the code below,

Table2 table2(Cfield cfield = this.cfield,
                                   boolean _forUpdate = false)
{
    return Table2::find(Cfield,_forUpdate);
}
Now drag drop the display method to the form of Table1
We we change the common field value the field value changes, Dont forget to change the properties of dragged form control.
                                                                Vivek Chirumamilla


Sunday 15 January 2012

How to add a image to a form in Ax 2009

Hi friends ,

   Today we are going to add a image to form below the grid to diplay the related image,
In form take a new group and add a window control to display the image.Add a button group and take a menu item button from it. The properties of menu item are as follows,
Property                           Value
Name                            CompanyImage
MenuItemType              Display
MenuItemName            CompanyImage
Text Item                       image
DataSource                  InventTable
In class declaration of your form declare a container and add a method on form of to load the images,
the code for form is as follows,

void loadImage()
{
    Image        img;
    CompanyImage companyImage;
    ;
    companyImage = CompanyImage::find(
        InventTable.dataAreaId,
         InventTable .TableId,
         InventTable .RecId);
    if (companyImage.Image)
    {
        img = new Image();
        img.setData(companyImage.Image);
        ItemImage.image(img);
    }
    else
    {
        ItemImage.image(null);
    }
}
Take a button under menuitem buton and name it as "save as"
to save the image which u have created  take a new method on form and write the following code

void saveImage()
{
    Image    img;
    Filename name;
    str      type;
    #File
    ;
    if (!imageContainer)
    {
       return;
    }
    img = new Image();
    img.setData(imageContainer);
    type = '.'+strlwr(enum2value(img.saveType()));
    name = WinAPI::getSaveFileName(
        element.hWnd(),
        [WinAPI::fileType(type),#AllFilesName+type],
        '',
        '');
    if (name)
    {
        img.saveImage(name);
    }
}

And write a active method in datasource properties
  element.loadImage();
 And in save button override the clicked method and write the code as following
 element.saveImage();
By this a image is displayed by using this functionality
        By vivek chirumamilla

Monday 9 January 2012

Create LookUp using X++ in Ax 2009

Hi Friends,

 Today we are going to create look up using code
1. Create a Form
2.Add a string Edit Control
3.In the methods of control write the following code

public void lookup()

{
//super();


// Declaration
Query   LookupQuery    =   new Query();

QueryBuildDataSource     LookupQueryBuildDataSource;

QueryBuildRange                  LookupQueryBuildRange;
SysTableLookup CustomSysTableLookup =       SysTableLookup::newParameters(tableNum(CustTable), this);

;

// Add fields that you want in Lookups

CustomSysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));

CustomSysTableLookup.addLookupField(fieldNum(CustTable,Name));

LookupQueryBuildDataSource =

LookupQuery.addDataSource(tableNum(CustTable));

LookupQueryBuildRange=

LookupQueryBuildDataSource.addRange(fieldNum(CustTable,AccountNum));

//LookupQueryBuildRange.value(queryValue(NOYESCOMBO::Yes));

// Execute the Query

CustomSysTableLookup.parmQuery(LookupQuery);

CustomSysTableLookup.performFormLookup();

}
Vivek Chirumammila

Friday 6 January 2012

How to open a form by using code

Hi friends ,

      Today we are going to open a form using code.. Its a simple way to do

 if(inventtable.Family == family::MettalicCore)
   {
   new MenuFunction(MenuItemDisplayStr(Attributes1),MenuItemType::Display).run();
    }
    else
    {
     new MenuFunction(MenuItemDisplayStr(Attributes),MenuItemType::Display).run();
     }
Here we are opening a form of Attributes1 and Attributes form its a simple way.Block Super()

Here is another way take a look


static void OpenFormByCodeB()
{ FormRun formRun;
Args args = new Args();
;
args.name(formstr(CustTable));
args.record(CustTable::find('ABC'));

formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
}

Now if we tweak this a little bit, we can add our code
Like this:

static void OpenFormByCodeB()
{ Object formRun;
Args args = new Args();
;
args.name(formstr(CustTable));
args.record(CustTable::find('ABC'));

formRun = ClassFactory.formRunClass(args);
formRun.init();

formRun.yourmethodgoeshere(); /* !!

formRun.run();
formRun.wait();
}

By changing the type of formRun from class FormRun to class Object, we can implement and execute extra methods on our destination form! This gives us extra possibilities for customizations. You can pass along extra parameters for example.
Only drawback: While programming, your method doesn't show up in the IntelliSense, showing all the available methods. So be carefull of typo's. (They don't give a compile error, but they will give you a run-time error.)
 Thank you bye
                                                                                      Vivek Chirumamilla