Args Concept Form to Class in AX 2012 R3 | D365fo

 


Form Button Click Code: 

void clicked()
{
    Args            args;
    MenuFunction    menuFunction;
    super();
    args    =   new Args();
    args.record(Products);
    args.parm(Products.ProductId);
    menuFunction = new MenuFunction(identifierStr(Product_ArgsClass),MenuItemType::Action);
    menuFunction.run(args);
}
//---------------------------------------

Write the code on class main 

public static void main(Args _args)
{
    Products            products;
    //Product_ArgsClass   argsClass;
    str                 parmId;
    ;
    //argsClass   =   new Product_ArgsClass();
    products    =   _args.record();
    parmId      =   _args.parm();
    info(parmId);
}

Download the Project.

Find and Exist methods for Tables in AX2012, D365fo

 Select statement of x++ retrieves data from data from database but why then find method in ax 2012?

Find method

static InventTable find(ItemId itemId, boolean update = false)
{
    InventTable inventTable;
    ;
    inventTable.selectForUpdate(update);
    if (itemId)
    {
        select firstonly inventTable
            index hint ItemIdx
            where inventTable.ItemId == itemId;
    }
    return inventTable;
}


Example: 2

Static YajTable find(Name _studentId, boolean  _Update = false)

{
    YajTable    yTable;
   
    yTable.selectForUpdate(_Update);
    
if (_studentId)
    {
        
select firstOnly yTable
            
index hint studentIdIdx
            
where yTable.StudentId == _studentId;
    }
    
return yTable;
}

-----------------------------------------------------------

Check the find method with Job.


1) of course, find method uses select statement to retrieve the data but it requires parameter

to search, if that exist, it searches otherwise it skips. that is one advantage of using find method. from example above, it accepts itemid as parameter, if it exist then it goes inside of if statement.

2) it accepts one more parameter i.e.,  boolean update which is false by default. Have a Boolean parameter with a default value of false. If true, the record should be selected for update.

3) Make the most effective select operation for the single record from the table and return it. Use an index that matches the required field, and use the firstOnly keyword (see the above example).

4) Have an optional parameter to enable the default Concurrency Model behavior specified on
the table to overruled. The default value for the parameter should be ConcurrencyModel::Auto. Usually, almost all the AX Tables have the OCCEnable Table property set to yes.
Optimistic Concurrency Control (OCC) helps increase database performance because the records are locked from the time when the actual update is performed.

5) you write exactly the same code as in find() method, then the behavior will be the same. The purpose of find() is that you don’t have to repeat it and method do more than just the select. Namely it doesn’t bother making any DB query if no value is provided and it has one or two extra parameters (_forUpdate and _concurrencyModel).

6) Run on both the client and the server. This is the default behavior. You can also make it explicit by putting “client server” in the declaration, but do not specify a single tier in the declaration (either the client or the server).

7) It is recommended to select a record from a table using this method based on primary key of the table, so that method returns only one record at a time.

8) find method is declared static because This method can be called from outside of the scope of table class.


Display and Edit Methods in AX 2012 R3 | D365fo

Display and Edit Methods are Custom methods.

Both methods used to call the field which are not available in the current form/table.

Display method restrict the user to edit the values in the field.

Edit method = Display method + Editing capability

Action Plan:

Create methods

1. Display method:  GetItemMethod

2. Edit Method: EditMethodItemName

Write the Code in both methods

then Drag and Drop the methods into form Design as Fields. then

method property    : give DataMethod as Method name, Datasource as primary table values as in the Image.



Download project

Multi Menu items for Single form to restrict fields | How to know opened/caller form MenuItem name?

Task Description:

 Open the form with help of 2 menu items. but One menu item display all available field from the form. the Second Menu item display few fields only from same form.

Solution:

form init identifies the which menu item calling this form then based on it restrict the fields from the form.






Download the Project

Delete Actions Table relation property - Cascade, Restricted and Cascade+Restricted in AX 2012 R3 | D365fo

Use of Cascade, Restricted and Cascade +Restricted (Delete action property for a table)



 Example of Cascade

Suppose we have two tables  (Customer & Order) and the relation is of One-To-Many i.e. Customer can have many orders

So on a parent table i.e.(Customer) if I set a delete action property to “CASCADE” for Order table. Then If I go and delete the record from a Customer table. It will also delete all the related records in Order table automatically

Example of Restricted

Suppose we have two tables  (Customer & Order) and the relation is of One-To-Many i.e Customer can have many orders

So on a parent table i.e.(Customer) if I set a delete action property to “RESTRICTED” for Order table. Then If I go and delete the record from a Customer table. It will first check the record in the child table and if exist that warning prompt saying that first we need to delete a record from child table.

Example of Cascade + Restricted

Suppose we have three tables  (Person ,Customer & Order) Now Person is a parent of Customer table, and Customer is a parent of Order table having (One-To-Many) relations

If I set a Delete action property on Person table to “CASCADE” for customer table  and If I set a  Delete Action property on a CUSTOMER table for Order table to “CASCADE +RESTRICTED”.

So if I delete a record from Customer table then It will first check the record in the child table(order table) and if exist that warning prompt saying that first we need to delete a record from child table.

But if I delete a record from Person table it will automatically delete a record in Customer table and all records related to customer table in Order table would also be deleted.

Cardinality and RelatedTableCardinality table relation property in AX 2012

Understanding the tables cardinality concept

As a trainer, I am often asked the question how to set the Relation’s properties in a table’s relations node, and how / where are those used, so, this would not necessarily be a new topic but rather a review of the concept:

- a relation between two tables is the fundamental way of describing how we view the data in a relational database;
- a relation is actually a column (FK - foreign key) on the second table pointing to a column (PK - primary key) in the first table, field that identifies uniquely a record;
- one table can be seen as the parent table and the other one, that will hold the relation the child table;
- you would create the relation always on the child table;
- the cardinality concept simply talks about how many records from the table in discussion we can have pointing to one record in the other table; we always relate as we would have one record in the other table, and looking from its perspective to the other;
- the Cardinality property refers to the table you are creating the relation on, so that would be the child table; the values for the cardinality can be: ZeroOne, ExactlyOne, ZeroMore, OneMore.  So, while on any record in the child table you could set the related columns value to point to one record in the parent table, you could actually have more child records looking at the same parent record, so from here the options above;
- the RelatedTableCardinality property refers to the parent table; the values can be: ZeroOne, ExactlyOne. Let us explain them. So for every child, you could have a parent for it or maybe no parent. If the relation's column would be mandatory, that means that from a design point of view your parent would always be required, so that would make it an ExactlyOne.

-------------------------------------------------------------------------------------------------------------------------------------------

    Specifically, the Cardinality property corresponds to the notation on the child table (SalesLine in this case). So it should be ZeroMore (0…*).


    RelatedTableCardinality property corresponds to the notation on the parent table (SalesTable). So it should be ExactlyOne (1:1).

Semantically, Cardinality specifies how many instances of SalesLine row can be related to a single instance of SalesTable row. ZeroMore means that for every sale order, there can be zero, or more sales lines related to it. If the business requirement dictates that you need to have at least one sales line to be able to create a sales order, the Cardinality would be OneMore (1:*).

RelatedTableCardinality specifies how many instances of SalesTable row can be related to a single instance of SalesLine row. ExactlyOne means that every sales line should belong to one and only one sales order.

Create Label with Wizard.

 





Table groups, Types of table groups in AX 2012 R3 | D365fo


The following table groups are available in Microsoft Dynamics AX:

TYPES OF TABLE GROUPS

Table group

Description

Framework

Tables that are used by the underlying Microsoft Dynamics AX frameworks, such as Application Integration Framework (AIF). These tables are created during installation and are not associated with configuration keys.

Group

Tables that are used to categorize the tables in the Main table group.

Main

Principal or master tables that contain data for central business objects. These tables typically hold static, base information.

Miscellaneous

Tables that have not been otherwise categorized. Miscellaneous is the default table group for new tables.

Parameter

Tables that contain parameters or setup information for tables in the Main table group.

Reference

Tables that contain reference data.

Transaction, Transaction header, and Transaction line

Tables that contain transaction data.

The tables in the Transaction header table group categorize the tables in the Transaction line table group.

There is a one-to-many relationship between a Transaction header table and Transaction line tables.

Worksheet, Worksheet header, and Worksheet line

Tables that contain information that is validated and made into transactions.

Unlike the data that is contained in the tables in the Transaction table groups, data in the Worksheet table groups is temporary.


Table group

Use this group for a table with these characteristics

Examples

Parameter

The table contains data primarily used as parameters or setup information for one of the main tables (a table that has a TableGroup property of Main).

The table typically contains only one record per company.

CustParameters, VendParameters

Group

The table contains data primarily used to categorize one of the main tables (a table that has a TableGroup property of Main).

There is a one-to-many relationship between a Group table and a Main table.

CustGroup, VendGroup

Main

The table is one of the principal tables in the application and contains data for a central business object.

The table typically holds static, base information.

There is a one-to-many relationship between a Main table and a Transaction table.

CustTable, VendTable

Transaction

The table contains transaction data.

The table is typically not used for data entry directly.

CustTrans, VendTrans

WorksheetHeader

The table typically categorizes information in the WorkSheetLine tables.

There is a one-to-many relationship between a WorkSheetHeader table and a WorkSheetLine table.

SalesTable

WorksheetLine

The table contains information to be validated and made into transactions.

In comparison to the data contained in a Transaction table, the data in WorkSheetLine tables is temporary and may be deleted without affecting system stability.

SalesLine

Miscellaneous

The table does not fit in any of the other categories. This is the default value for a new table.

TableExpImpDef



Table properties PrimaryIndex in AX 2012 R3 | D365fo

Default key: Surrogatekey (Recid 'Table's default field') 

User wants to define. 

if lookup is not showing required field.

do the following changes in the table.


Result








Query, Static Queries, Dynamic Queries, Query Classes | AX 2012 R3 | D365fo

 

Query is a way of asking questions of your database. With the Query module, you can select, group, and list records that meet a set of conditions you define.

Query performs two tasks.

First, it segments your database based on criteria you define.

Secondly, it groups records for quick reference and use in other areas of the program, such as Mail, Export, or Reports.

Types of Queries:  Static Query, Dynamic Query

 

Static query:

A static query is like taking a snapshot of your database at the time the query is created. Only the records selected when the query is first created will be included when the query is used in the program. Use static queries when doing global changes. The same constituents are still in the static query so you can easily find them again if the need arises. Output queries and merged queries are static.

  • A static query contains only those records which met the specified criteria at the time the query was created
  • Static keys are pointers to each record in your query. The number of static keys equals the number of records in your query
  • A static query is not updated when used in other modules such as Mail or Reports
  • Static queries can be re-run through Query and will be updated with new records meeting the criteria in the query

Dynamic query:

A dynamic query is automatically refreshed each time it is used. When you use a dynamic query, the program searches the database for any new records meeting the criteria you specify and adds them to the results. Use dynamic queries whenever you need the query to remain current (automatically refresh). For example, you have a query of volunteers. Each time you use that query for a report or mailing, you want to be sure that it includes everyone who is currently marked as a volunteer and does not include anyone who is no longer marked as a volunteer. Because a dynamic query automatically updates itself (refreshes), you know that it is current. Most queries that you run will be dynamic queries.

  • A dynamic query is updated every time it is run or used in other modules such as Mail, Reports, and Export.
  • The results of a dynamic query always reflect changes made since the last time the query was run
  • Because dynamic queries consist of an ever-changing group of records, an exact number of records does not appear on the query information screen. Instead, the number appears as N/A or ## (approx.).

 


Query

1.           Query

2.           QueryBuildDataSource

3.           QueryBuildRange

4.      QueryBuildFieldList

5.           QueryRun

6.           QueryBuildLink

   QueryBuildStaticLink

   QueryBuildDynaLink

7.           QueryFilter

   QueryHavingFilter

8.           QueryGroupbyField

9.           QueryOrderbyField

10.       QueryMiner

Query Classes

1.       addDataSource

2.       addRange

3.       Relations

4.       addLink

5.       FetchMode

6.       addHavingFilter

7.       addQueryFIlter

8.       addSortField

9.       addCompanyRange

10.   addBaseQuery

11.   dataSourceNo

12.   dataSourceName

Query Functions

·         QueryStr

·         QueryDatasourceStr


Simple Dynamic Query.



Dynamic Query with Multiple Tables and With Relationships.









Event Method Sequences when a Form is Opened

 

Event Method Sequences when a Form is Opened

An event method sequence is executed when a form is opened. The specific sequence depends on the set of controls and data sources that are associated with the form.

Open a Form

In this example, the user opens a form that contains a grid control, which is bound to a data source.

The executed events are distributed across two threads. The timing of event method execution between threads can vary.

The following table shows the sequence that event methods are executed in when a user opens a form.

OPEN A FORM

Method

Where

Thread number

new

Form

init

Form

1

loadUserSetting

Form

2

run

Form

1

init

Data source

2

executeQuery

Data source

2

leaveRecord

Data source

2

leave

Data source

2

leaveRecord

Data source

2

firstField

Form

2

firstField

Form

1

Table Browser in Dynamics 365FO

Copy D365FO Table Browser URL /?cmp=usmf&mi=SysTableBrowser&tablename= URL :  https://usnconeboxax1aos.cloud.onebox.dynamics.com...