Contact Me

Total Pageviews

Sunday, 10 August 2014

Lookup form To Display the values of Enumeration

We will use:

SysLookup::lookupEnum(SysDictField _sysDictField) in AX 2009. 

This method is used to display Enum Values on a Form control.

Override the lookup Method of the String Edit Form control and write :

public void lookup()
{
 this.performFormLookup(SysLookup::lookupEnum(new SysDictField(tableNum(SalesTable),  fieldNum(SalesTable, SalesType)))); //SalesType is a Enum Field of SalesTable.
}

That's it the form control will contain the SalesType enum Values now.

Note :

The Same method in Ax 2012 contains one more Parameter and the Syntax is :

client public static FormRun lookupEnum(SysDictField _sysDictField, [container _excludedEnumValues])

As you Can see using the Container you can filter Enum Values to be displayed in the Lookup on form control. 

To Filter enum Values on a form control in Ax 2009 refer to this post of my Blog.

Happy Daxing :)


Multi Table Lookup on a Form Field in Axapta

Sometimes, our client requires a  lookup with many information from two or more tables. The recipe below will show how to use Multiple Tables for lookup on a form field.


 public void lookup()
{
    Query                   query = new Query();
    QueryBuildDataSource    qbdsItem;
    QueryBuildDataSource    qbdsInventTableModule;
    QueryBuildDataSource    qbdsInventItemLocation;
    QueryBuildRange         qbrModuleType;
    SysMultiTableLookup     sysTableLookup;
    ;
    qbdsItem = query.addDataSource(tableNum(InventTable));

    qbdsInventTableModule = qbdsItem.addDataSource(tableNum(InventTableModule), "Purch");
    qbdsInventTableModule.relations(true);
    qbdsInventTableModule.fetchMode(QueryFetchMode::One2One);
    qbrModuleType = qbdsInventTableModule.addRange(fieldNum(InventTableModule, ModuleType));
    qbrModuleType.value(queryValue(ModuleInventPurchSales::Purch));

    qbdsInventTableModule = qbdsItem.addDataSource(tableNum(InventTableModule), "Invent");
    qbdsInventTableModule.relations(true);
    qbdsInventTableModule.fetchMode(QueryFetchMode::One2One);
    qbrModuleType = qbdsInventTableModule.addRange(fieldNum(InventTableModule, ModuleType));
    qbrModuleType.value(queryValue(ModuleInventPurchSales::Invent));

    qbdsInventTableModule = qbdsItem.addDataSource(tableNum(InventTableModule), "Sales");
    qbdsInventTableModule.relations(true);
    qbdsInventTableModule.fetchMode(QueryFetchMode::One2One);
    qbrModuleType = qbdsInventTableModule.addRange(fieldNum(InventTableModule, ModuleType));
    qbrModuleType.value(queryValue(ModuleInventPurchSales::Sales));

    qbdsInventItemLocation = qbdsItem.addDataSource(tableNum(InventItemLocation));
    qbdsInventItemLocation.relations(true);
    qbdsInventItemLocation.fetchMode(QueryFetchMode::One2One);

    sysTableLookup = SysMultiTableLookup::newParameters(this, query); //Use the Query for lookup

    sysTableLookup.addLookupField(fieldNum(InventTable, ItemId));
    sysTableLookup.addLookupField(fieldNum(InventTable, ItemName));
    sysTableLookup.addLookupMethod(tableMethodStr(InventTable, ConfigActive), 1, "Is configuration active?");
    sysTableLookup.addLookupField(fieldNum(InventTableModule, TaxItemGroupId), 2, false, "Purch Item Tax Group");
    sysTableLookup.addLookupField(fieldNum(InventTableModule, TaxItemGroupId), 3);
    sysTableLookup.addLookupField(fieldNum(InventTableModule, TaxItemGroupId), 4);
    sysTableLookup.addLookupField(fieldNum(InventItemLocation, CountGroupId), 5);

    sysTableLookup.performFormLookup();

}

Happy Daxing :-)


Thursday, 7 August 2014

Filter Enum Values on Form Lookup Ax 2012 / Ax 2009

Often there are requirements/ design changes, where we need to filter and display on a few enum values in a Form lookup.

Often enough, we need to restrict the user selection from a particular ComboBox. Creating a new BaseEnum specifically for this purpose is a really cumbersome solution, which later might lead to problems of maintenance.

To use this class, you need to know only one static method:
public static SysFormEnumComboBox newParameters(
    FormRun _formRun,
    int     _comboBoxControlId,
    enumId  _enumId,
    Set     _allowedEnumValuesSet,
    Form    _form = null)

And here is an example of how you would use it:
sysFormEnumComboBox = SysFormEnumComboBox::newParameters(element, 
    control::ComboBoxOnForm, 
    enumnum(SalesType), 
    enumSet);

which means that the control ComboBoxOnForm will be bound to BaseEnum Sales Type, containing only values, found in the Set enumSet.

This code basically filters the enum based on the values from Set.


public class FormRun extends ObjectRun
{
    SysFormEnumComboBox         sysFormEnumComboBox;
    Set                         enumSet;// = new Set(Types::Enum);
}

In init method of form:

    enumSet= new Set(Types::Enum);
    enumSet.add(SalesType::Blanket);
    enumSet.add(SalesType::Journal);
    enumSet.add(Salestype::Sales);

    sysFormEnumComboBox  =      sysFormEnumComboBox::newParameters(element,control::ComboBoxOnForm,enumNum(SalesType),enumSet);

     super();

Happy Daxing! :)

Wednesday, 6 August 2014

Adding a Custom Lookup to a Form Field in Axapta

In Dynamics AX one way you can add a custom lookup or drop down list to a form control by overriding the lookup method of the control.  Below is some example code for doing this.


public void lookup()
{
    SysTableLookup          sysTableLookup =
    SysTableLookup::newParameters(
                            tablenum(CustTable),
                            this);
 
    Query                   query;
    QueryBuildDataSource    queryBuildDataSource;
    ;
 
    sysTableLookup.addLookupfield(
                    fieldnum(CustTable,
                    AccountNum));
    sysTableLookup.addLookupfield(
                    fieldnum(CustTable,
                    Name));
    
 
    query = new Query();
 
    // Add datasource to the query
    queryBuildDataSource = query.addDataSource(
                           tablenum(CustTable));

    queryBuildRange = queryBuildDataSource.addRange(
                      fieldNum(CustTable, AccountNum));
   
    select firstonly AccountNum from custTable;
    queryBuildRange.value(queryRange(custTable.AccountNum, ''));
 
    sysTableLookup.parmQuery(query);
 
    sysTableLookup.performFormLookup();
}

Happy Daxing! :)



Tuesday, 5 August 2014

Run a Report from a Class in Axapta

Hi all,

There are several methods to run a Report Directly from a Class:

Method1 : Create a Class and write the following code in 'main()' method..

static void main(Args  args)
{ ReportRun reportRun;
  Args      args = new Args(reportstr('CustTransList'));
;
reportRun = new Reportrun(args);
reportRun.init();
reportRun.run();
}


Method2 : The RunBaseReport class is part of the RunBase Framework. Its main purpose is to provide a user interface before the report starts and pack business logic.

The RunBaseReport class has a lot of methods to define and change the behaviour.
Create a new class and extend the RunBaseReport class. At least two methods have to be changed to make the class work
  • main
  • lastValueElementName
The main method makes the class runable from an action menu item. The lastValueElementName returns the name of the report to be started. The framework uses the query from the report <xpp>

public static void main(Args _args) {
 ReportDemo demo = new ReportDemo();
 ;
 if(demo.prompt()) 
 demo.run();
}
Override lastValueElementName() :

public identifiername lastValueElementName()
{
 return reportstr("CustTransList");

}

Happy Daxing! :)


Monday, 4 August 2014

Pass Parameters Between a Form and a Class in Axapta

Hi, everybody!


Sometimes, we want to pass parameters between form and class, and we don't know how to do it easily. In this case, we want to pass the form datasource to the class.


First of all, we need to create a class and a menu item that calls this class. Afterwards, we put this Axapta x++ code in a clicked() method of a new button of the form:


Class name is DASEmplDuplication and Form is EmplTable.

void clicked()
{
   MenuFunction    mf;
   Args            args = new Args();
   ;


   args.record(EmplTable);


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


Meanwhile, in the main() method of the DASEmplDuplication class, we need to put this Axapta x++ code to get the datasource:


static void main(Args args)
{
    DASEmplDuplication  DASEmplDuplication;
    EmplTable           localEmplTable;
    ;


    if(args.record().TableId == tablenum(EmplTable))
        localEmplTable = args.record();

        info(strfmt("%1",localEmplTable.EmplId)); 
        //Process form's Datasource Record in Class
    ...
}

Sunday, 3 August 2014

Pass Parameters Between a Form and a Report in Axapta

"Args" class will be used.

Override the Clicked() method of the button on the form like this:

void clicked()
{
   Args         args;
   ReportRun    reportRun;
   ;
   super();
   args = new Args();
   args.name(Reportstr(CustomerTransactions));
   args.record(CustTable);    //CustTable is the Datasource of the Form
   reportRun = classfactory.reportRunClass(args);
   reportRun.init();
   reportRun.run();
   reportRun.wait();
}

Override "init()" method of the report:

public void init()
{
  if(element.args().record())
  {
    extCustTable = element.args().record();

  }
}

Override "Fetch" method:

public boolean fetch()
{

boolean ret;

if(extCustTable)  //Launched from the form for a selected record
{
       this.query().datasourcetable(CustTable).addRange(CustTable,AccountNum).value(extCustTable.Acc ountNum)  
//Run the CustTrans Report for the selected Account Number on "CustTable" form.            
}

ret=super();
return ret;
}