Professional Documents
Culture Documents
Microsoft Dynamics AX 2012: Forms/tables Methods Call Sequences
Microsoft Dynamics AX 2012: Forms/tables Methods Call Sequences
Microsoft Dynamics AX 2012: Forms/tables Methods Call Sequences
• Case 7: RunBase
Form opening
Form Opening
Form.init
• Used to retrieve and validate the calling parameters
• Initialize Controls : Visibility, Enable, Editable…
• Do not put code that affects DS in this method use DS.init instead
DS.init
• Set Data Source properties : AllowEdit, AllowCreate, AllowDelete…
• Create ranges, sorting and filters
• Cache methods to improve performance
• Not apply ranges values only if the ranges/links… are permanent
Form Opening
DS.linkActive
• This methods is called every time we activate a new record on the
calling form
• Applying links, ranges and updating design depending on the caller
record!
DS.executeQuery
• Applying ranges and filters values
• Avoid changing the query structure (create ranges, links…) at this
level as this method is frequently called
DS.active
• Updating design depending on the selected record
• Updating other Data Sources queries
Record creation
Record creation
DS.Create
• Add supplementary rules to validate the creation
• Modify creation process : example open a specific form for creation
DS.initValue
• Only to initialize fields with values that can not exists outside of the
form, example :
• Filter on the top of the form
• Values coming from a calling form/class
Table.initValue
• Assign a default value to fields
• Always call this method when creating records by X++ code even if
the method is empty : It may be overridden in a future version!
Field modification
Field modification
Control.validate - Control.Modified
• never!
DSField.validate
• Validate the value typed / chosen by the user against business rules
and data consistency
DSField.modified
• Modify value on other fields
• Implement field modification rules
When : code we want to implement is specific to the form, or depends on some data that
are only available on the form
Table.validateField, table.modifiedField
Same as DS methods. These methods are called what ever the form.
Field modification
In modifiedField methods, you should always make sure that the code you
have implemented will be cancelable if the user choose not save the changes
he made. Else you have to force the saving of the record!
Incorrect :
Correct :
Field modification
Lookup consideration
When you override the default lookup of a field to filter values that can
be chosen by the user. You should always override validateField or
validate to consider the case when the user type directly a value in the
field without using the lookup.
Record saving
Record saving
DS.validateWrite
• Validate business rules and data consistency (mandatory fields filled…) that
are form specific
Table.validateWrite
• Same as the DS equivalent but will be applied on all forms
DS.Write
• Updating other DS in the same form
• Override the normal saving process with some specific rules
Table.insert / Tables.update
• Implement specific rules : CUD other record, recalculate a value…
Record saving
• Avoid direct call to doInsert/doUpdate, as all business rules that are written
in insert/update are not executed. Only use direct call if :
1. Performance issues
2. You are sure that business rules implemented in insert/update are not applicable in your
use case.
Creation/update by X++ Code should be done using AxBC classes because they implement a Framework to
correctly validate fields values and business rules. This will be discussed in an other session.
Record deletion
Record deletion
Delete Actions
You should always remember to implement Delete Actions when your table is
linked to other tables! Forgetting this can lead to data inconsistency.
In X++ code you should always call Table.validateDelete before calling delete
Form closing
Form closing
Main
• Keep the code as minimum as possible
• Used to retrieve and validate calling parameters, instantiate a class objects
and initialize class object parameters
Construct
• Always create a construct method to encapsulate the new Method
InitParmDefault
• Use this method to default class variables/query with default values for the
first class run by the user.
HOW TO ?
How to acces form objects
• Control
element.control(element.controlId(formControlStr(FormName, ControlName)))
Or
AutoDeclaration
General rules
Modification
• Propriety : AllowEdit
• X++ : DataSourceName_ds.allowEdit()
Deletion
• Propriety : AllowDelete
• X++ : DataSourceName_ds.allowDelete()
NOT CORRECT
Making Buttons that allow creation/modification/deletion disabled doesn’t prevent doing
theses action. As there are shortcuts (Ctrl+N, Alt+F9…) that trigger the same events!
How to?
In some cases you may have to use QueryFilter and not QueryBuildRange. See :
- http://msdn.microsoft.com/en-us/library/hh745335.aspx
- http://msdn.microsoft.com/en-us/library/gg881181.aspx
How to?
A standard framework behind listPage will apply filter once a value is specified!
Contact me
Website
Phone
+212 (0) 6 36 12 50 02
Thanks for your time, and see you in the next Lab!
Please don’t hesitate to contact me if you find any error on the document or if you have
any questions.