1. Security Permissions
2. Interview Questions 3. AOD Files and Model Information
4. List of Classes for different Process
5. List of Best Practices
6.Contents of TDD.
==============================================================
Security
Permissions in AX 2012
We
can simply remember this like RDP (Role > Duty > Privileges)
Below steps will provide the
permissions for the whole Form/Report
1)
Create one Role [ AOT >
Security > Roles (or) System Administration > Setup > Security > Security
roles]
2)
Create one duty and add that
duty to the Role.
3)
Create one Privileges and add
that to the Duty.
4)
In the privileges entry point
added menu item
Set the Access Level
property for the Menu item in the Privileges entry point node.
5)
Assign created role to the user
[ System Administration > Common > Users ]
Permission for a
particular field in the Form/Report
1)
Go to Form > Permissions
> Read/Update/delete/Create
It will automatically works for the particular assigned role based
user because this ‘Form1’ is already added in the privileges entry point node
and added role.
==========================================================
1) Difference between conpeek and confind
Confind :- we can find the position of an item.
static void conFindExample(Args _args)
{
container c = ["item1", "item2", "item3"];
int i;
int j;
;
i = conFind(c, "item2");
j = conFind(c, "item4");
print "Position of 'item2' in container is " + int2Str(i);
print "Position of 'item4' in container is " + int2Str(j);
pause;
}
Conpeek:- we can get the item in a particular position
static void conPeekExample(Args _arg)
{
container c;
int i;
;
c = conIns(["item1", "item2"], 1);
for (i = 1 ; i <= conLen(c) ; i++)
{
print conPeek(c, i);
}
pause;
}
2) Method
overloading and Method overriding
X++ supports overriding, but it
does not support overloading.
Overriding a Method [AX 2012]
The methods in a class are inherited
by any class that extends it. You can alter the functionality of an inherited
method by creating a method in the subclass with the same name and parameters
as in the superclass. This is called overriding the method. For example:
// Superclass: Attribute
public class Attribute
{
int
objectVariable;
}
void methodAtt()
{
//Some
statements
}
// Subclass: ColorAttribute
public class ColorAttribute
extends Attribute
{
int
addedObjectVariable;
}
void methodAtt()
{
//Some
statements
}
ColorAttribute is a subclass of Attribute and therefore inherits the
method methodAttr. However, because ColorAttribute defines a method with the
same name and the same number of arguments, the method in the superclass is
overridden.
Static methods cannot be
overridden because they exist per class. To protect other sensitive methods, or
core methods, from being overridden, use thefinal modifier. In the example below, methodAtt is declared as final, and so it cannot be overridden in any class that
extends Attribute.
public class Attribute
{
int
objectVariable;
}
final void methodAtt()
{
//Some
statements
}
Note
|
You
should not specify new or finalize methods
as final.
|
Overloading
is where there is more than one method with the same name, but the methods have
different signatures (return type or parameter lists or both).
Overriding is
where the superclass's implementation of a method is altered by the subclass's
implementation of the method, but the signatures of both methods are the same.
3) DictTable and DictField Class
DictTable class is used to access information ralated to table. (if you want to access the fields of a record, where you do not know the field names ex:- table_name.(field_id)
)
DictField class is used to access information ralated to table fields.
DictField class is used to access information ralated to table fields.
static void dictJob(Args _args)
{
DictTable dictTable = new DictTable(tableNum(CustTable));
DictField dictField;
int counter, fieldId;
CustTable custTable;
anytype value;
select firstonly custTable;
for (counter = 1; counter <= dictTable.fieldCnt(); counter++)
{
fieldId =
dictTable.fieldCnt2Id(counter);
dictField = new
DictField(tableNum(CustTable),
fieldId);
if
(!dictField.isSystem())
{
value = custTable.(fieldId); //
value of the record will display
if(value)
{
info(strFmt('%1 = %2',
dictField.label(),
// field name will display
any2str(value)));
}
}
}
}
4) Difference between Array collection class
and x++ arry class
An Array collection class can
hold the objects.
x++ array class holds primitive data types such as str,int
5) What should we use to increase performance
while inserting, updating or deleting records from a table?
ANS:
· RecordSortedList: Allows you to insert multiple
records in one database trip. Use the RecordSortedList construct when you want
a subset of data from a particular table, and when you want it sorted in an
order that does not currently exist as an index.
Student student;
RecordSortedList
recordSortedList = new RecordSortedList(tablenum(Student));
recordSortedList
.sortOrder(fieldname2id(tablenum(Student),’StudentId’));
student.clear();
student.StudentID=”123″;
student.FirstName=”DOM”;
student.LastName=”FED”;
recordSortedList.ins(student);
student.clear();
student.StudentID=”456″;
student.FirstName=”TOM”;
student.LastName=”GED”;
recordSortedList.ins(student);
student.clear();
student.StudentID=”789″;
student.FirstName=”ROM”;
student.LastName=”TED”;
recordSortedList.ins(student);
recordSortedList.insertDatabase();
· RecordInsertList: Allows you to insert multiple
records in one database trip. Use the RecordInsertList construct when you do
not need to sort the data.
· insert_recordset: Allows you to copy multiple
records from one or more tables directly into another table on a single
database trip.
6) Difference between update and doupdate
The doUpdate table
method updates the current record with the contents of the buffer. This method
also updates the appropriate system fields.
The doUpdate method
should be used when the update method on the table is to be bypassed. Suppose you have overridden the update method
of the table but sometime there is a situation when you don't want the code
written in the overridden update method to be executed and at the same time
want any selected record of that table to be updated. In such situation you
should call the table.doupdate() method instead of table.update() method.
7) Collection Classes
you cannot store objects in arrays (x++ class) or containers.
The Microsoft Dynamics AX collection classes have been designed for storing
objects.
Below are collection
classes: Set , Map , List , Array
(Collection class)
A Set is
used for the storage and retrieval of data from a collection in which the members
are unique. The values of the members serve as the key according to which the
data is automatically ordered. Thus, it differs from a List collection class
where the members are placed into a specific position, and not ordered
automatically
by their value.
static void Set(Args _args)
{
Set setOne;
Set setTwo;
SetEnumerator enumerator;
Int value;
setOne = new
Set(types::Integer);
setOne.add(4);
setOne.add(6);
setOne.add(3);
enumerator = setOne.getEnumerator();
while (enumerator.moveNext())
{
value = enumerator.current();
info(strFmt("%1",value));
}
}
Output :- 3
4
6
A List object
contains members that are accessed sequentially. Lists are structures that can
contain members of any X++ type. All the members in the same list must be of
the same type.
static void List(Args _args)
{
List integerList = new List(Types::Integer);
ListEnumerator enumerator;
// Add some
elements to the list
integerList.addEnd(1);
integerList.addEnd(4);
integerList.addEnd(3);
// Set the
enumerator
enumerator = integerList.getEnumerator();
// Go to
beginning of enumerator
enumerator.reset();
//Go to the
first element in the List
enumerator.moveNext();
// Print
contents of first and second elements
info(strfmt("%1", enumerator.current()));
enumerator.moveNext();
info(strfmt("%1", enumerator.current()));
enumerator.moveNext();
info(strfmt("%1", enumerator.current()));
}
Output :- 1
4
3
A Map object
associates one value (the key) with another value. Both the key and value can
be of any valid X++ type, including objects. The types of the key and value are
specified in the declaration of the map. The way in which maps are implemented
means that access to the values is very fast.
static void Map(Args _args)
{
Map mapTest;
MapEnumerator enumerator;
mapTest = new
Map(Types::String, Types::Integer);
mapTest.insert("One", 1);
mapTest.insert("Two", 2);
enumerator = mapTest.getEnumerator();
while (enumerator.moveNext())
{
info(strfmt("Key - %1 , Value
- %2.",enumerator.currentKey(),enumerator.currentValue()));
}
}
Output:- Key - One , Value - 1.
Key - Two , Value - 2.
8) Difference between Containers
and Temp tables
·
Data in containers are stored and retrieved sequentially, but a
temporary table enables you to define indexes to speed up data retrieval.
·
Containers provide slower data access if you are working with
many records. However, if you are working with only a few records, use a
container.
·
Another important difference between temporary tables and
containers is how they are used in method calls. When you pass a temporary
table into a method call, it is passed by reference. Containers are passed by
value.
·
When a variable is passed by reference, only a pointer to the
object is passed into the method. When a variable is passed by value, a new
copy of the variable is passed into the method. If the computer has a limited
amount of memory, it might start swapping memory to disk, slowing down
application execution. When you pass a variable into a method, a temporary
table may provide better performance than a container.
9) Code profier
The Code Profiler measures
the execution time of individual lines of code. Use this tool to find
performance bottlenecks and to help understand code that was developed by
others.
Dev Work space > Tools > Code profiler
If you click on Profile Run button, call tree and profile lines will be there
10)
Maps (AOT Element)
Maps
define X++ elements that wrap table objects at run time. With a map, you
associate a map field with a field in one or more tables. This enables you to
use the same field name to access fields with different names but the same data
type in different tables. Map methods enable you to create or modify methods
that act on the map fields.
A
table can be accessed through more than one map. Typically, if more than one
map accesses the same table, each map accesses different subsets of fields in
the table.Maps don't define database objects and so they aren't synchronized
with the database.
The benefits of maps
include:
Simplicity - maps provide a single
interface to fields in multiple tables. This means that any object referencing
the map field can be used against multiple tables without changing any field
names.
Consistency - table fields with varying
names can be accessed in code in a consistent manner. For example by using a
map, fields named Zip in one table, ZipCode in another, and PostalCode in yet
another table can all be accessed by the name ZipCode.
Code
reuse - a map method enables you to add code that runs against the map
fields. A single map method prevents the duplication of methods and code on
each table.
An example of a map in
Microsoft Dynamics AX is the Address map, which can be used to access fields in
two tables (among others) called Address and CustVendTransportPointLine. This
enables developers to use one Address map object to access common address
fields and methods.
Map Elements: In Microsoft
Dynamics AX, maps are located in the Application Object Tree (AOT) under the
Data Dictionary\Maps node. Each map has four primary elements:
- Fields
- Field Groups
- Mappings
- Methods
Fields: The Fields node contains
the map field elements. Each field must be the same data type as the field to
which it's associated. Use the ExtendedDataType property to specify the map
field's data type if the map field is associated with a table field that's
based on an extended data type.
Field Groups: The Field Groups node
contains field groups that group together fields that logically belong
together. Field groups in maps work the same way they do in tables. For more
information about field groups, see Best Practices for Field Groups, Defining
Field Groups, and How to: Create a Field Group.
Mappings:
The Mappings node is where the map fields are associated with
table fields. Directly under the Mappings node are the MappingTable objects.
Each MappingTable object specifies a table that the map is associated with.
Under the MappingTable object are the field mappings that associate a map field
with a table field. If a field exists in the map with no associated field in a
particular table just leave the MapFieldTo property blank.
Methods: This node displays all the
methods available from a map. In this node you can add a new method or you can
override methods on the xRecord kernel class and add your own code.
Map
methods are useful because code that acts on the map fields can be encapsulated
in a map method instead of being in multiple table methods. For example, the AddressMap has a
formatAddress method that formats the address consistently whether the map
references the Address table or the CustTable table.
11)
Temp Tables
From a developer's perspective, temporary tables
store data in the same way as normal physical tables, except that the data is
automatically dropped when no longer required.
They are useful in two common situations
1.
As the datasource for a form or report, where the original data is
too complex to be easily queried.
2.
As temporary storage during complicated processing, to hold the
results midway through the process.
Prior to Dynamics Ax version Ax 2012, only one
type of temporary table was available. In Ax 2012, however, the Temporary property
on tables was replaced with a new property: TableType, which has
three possible values:
§ Regular - a standard physical table
§ InMemory - the type of temporary table which existed in the previous
versions of Dynamics Ax. Such tables are held in memory and written to a local
disk file once they grow beyond a certain point
§ TempDB - a new option in Ax 2012. They are "physical"
temporary tables held in the SQL Server database.
The new TempDB tables operate
in a similar manner to InMemory tables but support more
features from standard physical tables:
§ More powerful joins with physical tables are
possible, and are properly supported by the database
§ Can be per-company or global
Support
for normal tts transactions
AOD files path:-
C:\Program Files\Microsoft
Dynamics AX \ 60 \ Server\ MicrosoftDynamicsAX\bin \Application \Appl \Standard
The following table
shows the names of the layers in different versions of Microsoft Dynamics AX.
Microsoft Dynamics AX 4.0 layer
|
Microsoft Dynamics AX 2009
layer
|
Microsoft Dynamics AX 2012
layer(Rename to this)
|
axbup.aod
|
axbup.aod
|
axisp.aod
|
axbus.aod
|
axbus.aod
|
axisv.aod
|
axlop.aod
|
axsl3.aod
|
axslp.aod
|
axlos.aod
|
axsl2.aod
|
axsln.aod
|
axdip.aod
|
axsl1.aod
|
axfpp.aod
|
axdis.aod
|
axhfx.aod
|
axfpk.aod
|
Model
A model is
a set of elements in a given layer. Each layer consists of one or more models.
Each layer contains one system-generated model that is specific to that layer.
Every element in a layer belongs to only one model. In other words, no element
can belong to two models in the same layer, and every element must belong to a
model.
A model is permanently associated with the layer that the model
was created in. If you need to move one of your models from one layer to
another, you must create a project from the model in the Application Object
Tree (AOT), export the project as an xpo file, create a target model in the
desired layer, delete the original model to avoid having to resolve layer
conflicts, and import the xpo file to the target model. If you are moving
elements between models in the same layer, you can use the Move to model command in the AOT.
Models are stored in the model store. The model store is a database in which all application elements for
Microsoft Dynamics AX are stored. Customizations are also stored in the model
store. The model store replaces the Application Object Data (AOD) files that
were used in earlier versions of Microsoft Dynamics AX. Models that have been
installed in the model store are used at run time.
Models can be exported to files that have the .axmodel
extension. These files are called model files. Model files are deployment
artifacts. Model files can be signed with strong name signing and Microsoft
Authenticode signing.
Models can be exported to files that have the .axmodel extension
Models are logical group of element like tables and classes. In
AX 2012 elements can be group and store in the model file. Model files are easy
to create, export, import and this can be uninstalled from the system when not
required.
Models can manage through following tools.
·
AXUtil.exe command-line
utility.
·
Programmatically; using
axutilib.dll
·
PowerShell.
Create Model:-
1)
using Developer workspace
Tools > Model management
> Create model
2)
Using AXUtil
C:\Program
Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\bin> axutil create
/model:SuniTest /layer:USR
Create Project from model:-
Developer workspace >
Tools > Model management > Create Project from model
Export Model
Syntax: axutil export /model:<modelname>
/file:<filename>
C:\Program Files\Microsoft
Dynamics AX\60\ManagementUtilities>axutil export
/model:"SuniTest"
/file:"ExportModel_TestSuni"
Import Model
Syntax: axutil import /file:<filename>
C:\Program
Files\Microsoft Dynamics AX\60\ManagementUtilities> axutil import /file:” ExportModel_TestSuni.axmodel”
Delete Model
Syntax:
AxUtil delete /model:"My Model"
=============================================================================
Sales Order
SalesOrder Main
list page -> SalesTableListPage(Form) , SalesTable
(Table)
Salesorder
Header and Line view page -> SalesTable
(Form) , SalesLine(Table)
Purchase Order
Purchase Order Main
list page -> PurchTableListPage(Form), PurchaseTable (Table)
Purchase order Header
and Line view page -> PurchTable(Form), PurchLine
(Table)
When we are doing Confirmation/Packlingslip/Invoice
, it will open one form related table
Classes: - SalesFormLetter_Confirm, SalesFormLetter_PackingSlip, SalesFormLetter_Invoice, PurchFormLetter_Invoice,
PurchFormLetter_PackingSlip
Tables: -
SalesParmTable, PurchParmTable ( when u r doing invoice/pakingslip,one form
will open.These tables are related to that forms)
Form: -
SalesEditLines, PurchEditLines (when u r doing invoice/pakingslip, one form
will open.These forms are related to that forms)
Ledger
GeneralJournal :- main
form and table -> LedgerJournalTable(Form,Table)
Lines form -> LedgerJournalTransDaily(Form),
LedgerJournalTrans(Table)
For ‘Post’ and ‘PostandTransfer’ button means when u
post the journal -> LedgerJournalPost(class)
and LedgerJournalCheckPost (Class)
For ‘Validate’ botton
-> LedgerJournalCheck (Class)
Inventory
Inventory Movement/Transfrer (when moving items from one inventory to another inventory) - >InventJournalCheckPost
What
are the best practices you follow?
1)
Select statement
·
If you are going to use only
the first record or if only one record can be found, use the firstOnly
qualifier. This optimizes the select statement for only one record.
·
The index, order by, and where statements are indented once relative to the select or while select statements.
select firstOnly
ledgerTrans
index hint DateIdx
order
by accountNum, transDate
where
ledgerTrans.accountNum >= '40000'
&&
ledgerTrans.accountNum <= '99999'
&&
ledgerTrans.transDate >= 26\04\1999
&&
ledgerTrans.transDate <= 02\05\1999;
2)
Use switch statements instead of nested if...else statements.
3) ttsBegin and ttsCommit
4)
Try / Catch
Always
create a try/catch deadlock/retry loop around database transactions that might
lead to deadlocks.
Whenever you have a retry, all the
transient variables must be set back to the value they had just before the try.
The persistent variables (that is, the database and the Infolog)
are set back automatically by the throw that leads to the catch/retry.
try
{
this.createJournal();
this.printPosted();
}
catch
(Exception::Deadlock)
{
this.removeJournalFromList();
retry;
}
5) The throw statement automatically
initiates a ttsAbort, which is a database
transaction rollback.
The throw statement should be used only if a piece of code cannot do what
it is expected to do. The throw statement should not be used
for more ordinary program flow control.
Always place an
explanation of the throw in the Infolog before
the actual throw.
Do not use ttsAbort directly; use throw instead.
6) Use DateTimeUtil::getSystemDateTime instead of systemDateGet or today. The today function uses
the date of the machine. The systemDateGetmethod uses the system date in Microsoft Dynamics AX. Only DateTimeUtil::getSystemDateTime compensates for
the time zone of the user.
7) Indentation
An
indentation is equivalent to four (4) characters, which corresponds to one tab
in the X++ editor.
8) Extra Semicolon is No Longer
9) Constants : Use global
macros
10) Put comments in your
code, telling others what the code is supposed to do, and what the parameters
are used for.
======================================================================
No comments:
Post a Comment