Tuesday, July 31, 2007

Dynamics AX Programming of Basic Methods of Tables

Definition and modification of methods in tables

When a new table in the Tree of Objects of the Application is created, MorphX automatically creates a series of methods for her. Adding X++ code to these methods we can modify the predetermined behavior of the system.
In addition, we can define our own methods. The methods of system and the user defined ones share he himself scope, therefore it is possible to add new methods that can be used from the methods defined by the system. As well as to accede to the system methods from any new method.
It is important to indicate that we cannot modify the type of return, the list of parameters or the type of these parameters in the methods defined by the system, although we can add additional parameters whenever we declare a value predetermined for them.

Methods of system

The system methods are executed when the table is used, for example, when we introduce, updated or erased data.
The body of these methods initially contains a call to the super method solely (). In later chapters method will be described with more east detail. To at the moment it is enough us with knowledge that corresponds to the predetermined behavior of the system. When X++ code is added to the methods defined by the system, east behavior is overloaded.
Next they appear the list of methods of system of a table. In later sections they will be described with more detail most important.

Method

It is executed when…

Caption

is the head of a form. The text is generated from the properties of the table.

Clear

the fields of the present registry erase (they have values NULL).

Delete

a registry is eliminated.

HelpField

the text of aid of a field is in the state bar, for example when we happened to the following field in a form.

InitValue

It initializes the fields of a registry just created.

Insert

a new registry in the table is introduced.

Merge

two registries are united or combined.

PostLoad

a registry is loaded.

RenamePrimaryKey

renombra the primary key of the table.

ReRead

a registry is reread.

ToolTipField

the leader of the mouse is located in a field of a form.

ToolTipRecord

one is going away to show an advice for the present field. The super method () makes a call to Caption.

Update

before modifying an existing registry.

ValidateDelete

one is going away to erase a registry.

ValidateField

a field give ins, for example when we jumped to the following field of a registry.

ValidateWrite

before writing a registry in the data base.

Methods of validation in tables

The validation methods allow the programmer to verify that certain conditions are fulfilled before an action is executed.
In Axapta, methods of validation at two levels can be programmed:

  1. Table
  2. Origin of data of a form

It is important to know that the methods of validation of the tables are executed whenever they are introduced or erase registries. Whereas if the validation is made in the form, it will only work when we are working with that form.

  1. Whenever it is possible, the validation of data must be made in the table.

Methods

The methods of validation in tables are the following ones:

ValidateField

It is executed when we move the cursor from a field from the form to another one, that is to say, when we left a field. It gives back a data of boolean type. If the result is false, the cursor will remain in the field.
The call to the super method () verifies the validation relations, that is to say, relations in a field where the Validate property has affirmative value. Therefore, we must respect the task made by this super method ().

  1. Validations do not have to be codified that can be made with some property. Thus, we will avoid to write code in the ValidateField method if the conditions can be verified with the Validate property of a relation.
ValidateWrite

It is executed before inserting or updating a registry in the table. It gives back a data of boolean type. If it gives back false, the registry is not inserted or updates.
The call to the super method () examines all the fields to verify the value of the Mandatory property. Therefore, we must respect the task made by this super method ().

  1. We will avoid to introduce code that it verifies if a field has value, whenever we pruned to use the Mandatory property.
ValidateDelete

It is not necessary to forget, that often also we want to verify certain conditions before erasing a registry of a table. In order to do this, we used the ValidateDelete method ().
ValidateDelete () is called automatically from forms and is used to verify if the present registry can be erased.
The call to the super method () verifies if there are registries related in tables to DeleteActions of the Restricted type. If that is the case, the super method () gives back false. Therefore, we must respect the task made by this method.

  1. Whenever we pruned to use a DeleteAction, we will avoid to introduce code in the ValidateDelete method.

Structure of the validation methods

In order to maintain a good structure of programming, he is recommendable that the code for the verifications is not located directly in these methods of validation. It is more advisable than we create verification methods that will be called from the methods of validation previously described.
Example of validation method
Boolean validateWrite ()
{
Boolean ret;

ret = checkSomething () && checkSomethingElse ();

return ret;
}
When some of the conditions is not fulfilled, the verification method must make two things:

  1. to present/display to the user an error message
  2. to give back the false value like result

The CheckFailed method (`Message of error') writes the text chain that receives as parameter in the information window (Infolog) and gives back the false value. Therefore, by means of the use of this method, we obtained simultaneously both objective.
Example of use of CheckFailed
Boolean checkSomething ()
{
Boolean ret;

if (! something)
{
ret = checkFailed (`Something is wrong');
}
return ret;
}
We could use the previous structure, but cases exist in which it interests to us to verify the same Something condition, present in the CheckSomething method (), without presenting/displaying no message to the user. In this case we would need an additional method, that verified the condition but that it did not show any message.
Nevertheless, this would not be very efficient, because we would be duplicating the verification code, therefore is more recommendable to create a called method Something (), to which we will be able to call when we want, that it will be in charge to make this verification.
We will have, in addition, to change the CheckSomething method (), so that it makes a call to this new method. The CheckSomething method () we will use it solely when we want to show a message the user.
Example of complete validation
Boolean something ()
{
if (! something)
{
return false;
}
return true;
}

Boolean checkSomething ()
{
Boolean ret;

if (! something ())
{
ret = checkFailed (`Something is wrong');
}
return ret;
}

  1. We can consider a standard of nomenclature of Axapta, the use of the Check area code, in the name of all those methods that make a call to the global method CheckFailed (). Of this form we will know what methods present/display messages in the Infolog window.

Used methods of system more

Next we are going to describe some of the used methods more in the tables, that by their importance deserve a treatment something more exhaustive. The examples of the methods have been obtained from the CustTable table.

InitValue

The InitValue method is executed when we added a new registry. Also it is called automatically from the forms. Therefore, we will use the method to assign initial values or by defect in a new registry.
Example
void initValue ()
{
CustParameters custParameters;

super ();
this.languageId = CustParameters:: languageId ();
this.currency = CompanyInfo:: find () .currencyCode;
}
It is necessary to indicate that the call to the super method () does not do anything.

Insert

The Insert method is executed when a new registry in the table is introduced. It is very important to assure any related transaction to assure integrity the data base. The techniques of control of transactions will be seen in a later chapter.
Example
void insert ()
{
this.setNameAlias ();
super ();
}
If the registry cannot be inserted in the table, the call to the super method () gives back an error.

Update

The Update method is executed before modifying an existing registry in the table. In this case, also it is very important to control any related transaction to assure integrity the data base.
Example
void update ()
{
CustTable this_Orig = this.orig ();

ttsbegin;
this.setNameAlias ();
super ();
this.setAccountOnVend (this_Orig);
if (this_Orig.custGroup! = this.custGroup)
ForecastSales:: setCustGroupId (this.accountNum,
this_Orig.custGroup,
this.custGroup);
ttscommit;
}
In the example the method is used orig (). This one method gives access us to the registry before the update.

Delete

The method delete is executed when a registry is eliminated. It is very important to assure any related transaction to assure integrity to us the data base.
Let us suppose two related tables calls TableA and TableB. If in TableA we have defined a DeleteAction of type cracked (Cascade) with respect to TableB, when a registry of TableA erases erase the registries related in TableB.
For yield reasons, one is due to avoid to write code in the Delete method of these related tables (in the example, TableB). If code has not been added, the cascade erasures can be made quickly by the system database manager using directly instructions of erasure SQL.
Nevertheless, if we added code in those tables (what it can be necessary in some occasions), the system creates an instruction while select and executes the Delete method in all the tables related daughters. Of this form the yield is minor that when we directly used instructions of erasure in SQL.


18 comments:

  1. Hello everyone I work every day with Dynamics AX Programming of Basic Methods of Tables and this information is very complete and very useful, thanks for sharing

    ReplyDelete
  2. hi all
    http://www.tor.com/community/users/thinquisalci1978
    http://www.tor.com/community/users/linkmarete1981
    http://www.tor.com/community/users/proffinmimi1974
    http://www.tor.com/community/users/pebacklobtia1986
    http://www.tor.com/community/users/ophporisxa1980

    ReplyDelete
  3. Hello sir,
    I am new in axapta and just joined the company, I don't have
    much knowledge of coding in X++. So can u please provide me some imp
    materials like
    *1:-* How to do validations in a form.
    *2:- *How to make use of classes.
    and also other documents which u thought will be benefitial for me.
    My email id is-pgspranav2@gmail.com

    ReplyDelete
  4. Hello sir,
    I am new in axapta and just joined the company, I don't have
    much knowledge of coding in X++. So can u please provide me some imp
    materials like
    *1:-* How to do validations in a form.
    *2:- *How to make use of classes.
    and also other documents which u thought will be benefitial for me.
    My email id ajayram70@gmail.com

    ReplyDelete
  5. very interesting thanks for posting about Dynamics AX Programming of basic methods of tables

    ReplyDelete
  6. Hi there.. Thanks for sharing such a great article. Keep adding new articles so we can learn from you.

    ReplyDelete
  7. Hello there. I like your blog so much that i read every post of ours.
    http://helpbestessay.net/crm-developers-working-on-the-creation-of-plans/

    ReplyDelete
  8. Thanks for sharing valuable information. Your blogs were helpful to Azure learners. I request to update the blog through step-by-step. Also, find the Azure news at
    Such an ideal piece of blog. It’s quite interesting to read content like this. I appreciate your blog Data Science Course

    ReplyDelete
  9. This post is much helpful for us. This is really very massive value to all the readers and it will be the only reason for the post to get popular with great authority.
    Devops Training in Chennai
    Devops Certification in Chennai
    Big Data Training in Chennai
    German Classes in Chennai
    German Language Classes in Chennai
    Python Training in Chennai
    Devops Training in Adyar

    ReplyDelete
  10. Great post! I am actually getting ready to across this information, It's very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.

    Health Care Tipss
    All Time With You
    Article Zings
    Article Zings
    Article Zings
    Article Zings
    Article Zings
    Article Zings
    Health Carinfo

    ReplyDelete
  11. A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive
    Thanks For Sharing
    Types Of Obesity
    Expensive Workout Equipment
    Blood Pressure and Weight
    Successful Journey Through Recovery
    homemade laxatives
    Deal With Stress
    How Much Do You Really Owe Your Ex?
    Can Mangosteen Cure Diabetes

    ReplyDelete
  12. I am really happy to say it’s an interesting post to read. I learn new information from your article; you are doing a great job. Keep it up…

    Data Science Training in Gurgaon
    Data Analytics Training in Gurgaon
    Selenium Training in Gurgaon

    ReplyDelete
  13. We are well established IT and outsourcing firm working in the market since 2013. We are providing training to the people ,
    like- Web Design , Graphics Design , SEO, CPA Marketing & YouTube Marketing.Call us Now whatsapp: +(88) 01537587949
    : Digital Marketing Training
    Free bangla sex video:careful
    good post outsourcing institute in bangladesh

    ReplyDelete
  14. Very useful information to everyone thanks for sharing, learn the latest updated Technology at
    Best Training institutions in Gurgaon

    ReplyDelete
  15. Good. I am really impressed with your writing talents and also with the layout on your weblog. Appreciate, Is this a paid subject matter or did you customize it yourself? Either way keep up the nice quality writing, it is rare to peer a nice weblog like this one nowadays. Thank you, check also virtual edge and friendly introvert

    ReplyDelete
  16. Take a class for Python Training within Hyderabad and begin your bright career in this field by enrolling in AI Patasala. Students can pursue their careers through this Python course.
    aAI Patasala Python Course

    ReplyDelete
  17. It was a great experience after reading. Informative content and knowledge to all. Keep sharing more blogs with us.
    Data Science Training and Placements in Hyderabad

    ReplyDelete