Thursday, March 13, 2014

Table and Class

Table variables are declared on the basis of the data dictionary in MorphX; that is, on the basis of the tables, which are declared in the AOT. In most respects, table variables can be considered objects. Contrary to objects, they are not allocated explicitly. Only a variable declaration is required.
All tables are compatible with the Common table in the same way that all objects are compatible with the Object class. Table variables, which are declared as common buffers, can be used to hold data from any table. You cannot access tables without table variables.

public void myMethod()
{
    // Declares and allocates space for one CustTable record
    CustTable custTable;
}

Thursday, March 6, 2014

Event Sequence

Sequence of Methods calls while opening the Form
Form --- init ()
Form --- Datasource --- init ()
Form --- run ()
Form --- Datasource --- execute Query ()
Form --- Datasource --- active ()

Sequence of Methods calls while closing the Form
Form --- canClose ()
Form --- close ()

Sequence of Methods calls while creating the record in the Form
Form --- Datasource --- create ()
Form --- Datasource --- initValue ()
Table --- initValue ()
Form --- Datasource --- active ()

Sequence of Method calls while saving the record in the Form
Form --- Datasource --- ValidateWrite ()
Table --- ValidateWrite ()
Form --- Datasource --- write ()
Table --- insert ()

Sequence of Method calls while deleting the record in the Form
Form --- Datasource --- validatedelete ()
Table --- validatedelete ()
Table --- delete ()
Form --- Datasource --- active ()

Sequence of Methods calls while modifying the fields in the Form
Table --- validateField ()
Table --- modifiedField ()
 

Tuesday, March 4, 2014

Call Form from code

   if (mbsConfigSetting::Boolean(#BD71))
   {
        args = new Args();
        args.name(formstr('mbsbdcustFiscalTable'));
        args.record(custtable);
        formrun = ClassFactory.formRunClass(args);
        if (formRun)
            {
            formRun.init();
            formRun.run();
            formrun.wait();
            }
        }
   }

 Args                args;
    FormRun             formRun;
   args = new Args();
   args.parmEnumType(eNumNum(InventJournalType));
   args.parmEnum(InventJournalType::Count);
   args.record( InventJournalTable::find(this.TaskSourceId));
   formRun = new MenuFunction(menuitemdisplaystr(InventJournalTableCount), MenuItemType::Display).create(args);
   if (formRun)
    {
            formRun.run();
            formRun.detach();
    }

 

Monday, February 17, 2014

Surrogate Key

Surrogate Key


When a primary index is not specified, Microsoft Dynamics AX uses a Surrogate Key as the primary index. This key is the RecId field and, if the table is saved per company, the DataAreaId. The surrogate key is used on many relations between tables.

Sunday, February 16, 2014

Form Query

Use the query object to modify the query of a form data source. The query object can be retrieved using either <name of data source>_Q or FormDataSource.Query()
To make a permanent modification of the query, this is typically implemented in FormDataSource.Init() after the call to super().

To filter records in a form perform the following steps.
1.      In the ClassDeclaration, declare the relevant QueryBuildRange or QueryFilter objects.
2.      In FormDataSource.Init, initialize the range object.

3.      In FormDataSource.ExecuteQuery, assign the actual values to the ranges before call of super().

Combine the sorting with some aggregated fields, which makes the data source display aggregate information from the table instead of transactions. Perform the following steps to show the sum of quantity of inventory transactions shown per Item Id:
1.      Group the data by item id using the addGroupByField on the datasource.
Add Sum(Qty) as a SelectionField

public void init()
{
    QueryBuildDataSource dataSource;

    super();

    dataSource = this.query().dataSourceTable(tableNum(InventTrans));
    dataSource.addGroupByField(fieldNum(InventTrans, ItemId));
    dataSource.addSelectionField(fieldNum(InventTrans, Qty), SelectionField::Sum);
}

Args

If the caller is activating the called object by a menu item the Args object is automatically initialized and sent as a parameter to the object called. AOT properties of the menu item will be used.


If the called object is a form or a report, it can automatically apply to the information send by the Args object. Forms will automatically try to make a delayed synchronize with the args.record().

Friday, February 14, 2014

Query -- Exists Join

Combine records from one table whenever a value exists in a common field in another table.

Display inventory items the providing vendor who has been blocked.
    InventTable inventTable;
    VendTable vendTable;
    ;

    ttsbegin;

    while select forupdate inventTable
     exists join vendTable
      where vendTable.AccountNum == inventTable.PrimaryVendorId &&
vendTable.Blocked == CustVendorBlocked::All
    {
        inventTable.PrimaryVendorId ="";
        inventTable.update();
    }
    ttscommit;

Display only those customers which have at least one sales order in sales table. 
Query                   query;
QueryBuildDatasource    datasource,SalesDataSource,CustomerDataSource;
QueryRun   queryrun;
CustTable custtable;
SalesTable salesTable; 

query = new Query();
CustomerDataSource  = query.addDataSource(tableNum(CustTable ));
SalesDataSource  = CustomerDataSource.addDataSource(tableNum(SalesTable ));
SalesDataSource.joinMode(JoinMode::ExistsJoin   );

SalesDataSource.relations(false);
SalesDataSource.addLink(fieldNum(CustTable, AccountNum),
fieldNum(SalesTable  , CustAccount ));
queryrun = new QueryRun(query);
while(queryRun.next())
{
custtable = queryRun.get(tablenum(CustTable ));
Info(custtable.AccountNum);
}