Tuesday, 15 December 2015

How to pass parameters from Form to Class

here we want to pass the value from the form to class.
if (args.caller() && formHasMethod(args.caller(), identifierstr(M)))
 {
        formRunObject = args.caller();
        formRunObject.M();    
}

this code does not work in ax 2012 but it works fine in ax 2009.

 here  we have to create a class , a menu item as action   and then call this menu item in form's click method and then pass the value in the class through menu item and  catch the vaulue in the main method of class.

First create a form  demo form with a table called demo table where we will have only one field over there   and one grid in design and one button over there.



then create a class1


create a menu item with action type and assign the class to that.



then write the click method of that button as 

void clicked()
{
    //super();

    MenuFunction    mf;
    args            args = new Args();
    ;


    args.record(DemoTable);


    mf = new menufunction(identifierstr(MenuItem1), MenuItemType::Action);
    mf.run(args);
}

now open the form and insert a record and click the button you will get output as 


Monday, 14 December 2015

Table methods using ValidateWrite() ValidateDelete() initValue() ModifiedField()

Table methods using ValidateWrite() ValidateDelete() initValue() ModifiedField()

initValue()This method file while creating new record to initialize a value, here I am assigning user id to the userID field.

public void initValue()
{
super();
this.UserId = curuserid();
}

ValidateDelete()While deleting a record if we want to put any validation we can use this method. Here once I delete a record populating a info that deleted record.

public boolean validateDelete()
{
boolean ret;
ret = super();
info(this.AccountNum);
return ret;
}

ValidateWrite()

This method will get to fire when we update a record. here I am using to check mandatory field for address AccountNum

public boolean validateWrite()
{
boolean ret;
;
if(this.Address != "")
ret = super();
else
warning(" Please fill the address value");
return ret;
}

ModifiedField()

This method will execute if modified a record value, this works based on the field value.
Here I am using to fill the name field value according to the AccountNum

public void modifiedField(fieldId _fieldId)
{
CustTable ct;
;
super(_fieldId);
switch(_fieldId)
{
case fieldNum(Cust_new,AccountNum) :
{
this.Name = CustTable::find(this.AccountNum).Name;
}
break;
}
}

Definition and modification of methods in tables

When a new table in the Tree of Objects of the Application is created, MorphXautomatically 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 theMandatory 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 toDeleteActions 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 ofTableA 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 Deletemethod in all the tables related daughters. Of this form the yield is minor that when we directly used instructions of erasure in SQL.

Monday, 26 October 2015

What are the classes involved in Journal,PO and SO Posting with Invoicing.



1. Journal Posting: LedgerJournalCheckPost Class.

2. Sales Order Posting: SalesFormLetter  Class and SalesFormLetter_Invoice Class.

3. Purchase Order Posting: PurchFormLetter classes and PurchFormLetter_Invoice Classes.

Wednesday, 29 July 2015

Sequence of methods in the FORM level in AX

This gives the information of method calls in the form level while
1. Opening the Form.
2. Creating/Updating/Deleting the record in the Form.
3. Closing the Form.
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, 28 July 2015

Code Profiler in Dynamics AX 2012

Code Profiler in Dynamics AX 2012


There is a very good feature called code profiler. The Code Profiler measures and records the execution of each line of code, the time taken by each line ,the Parent(caller) and the child of the each lines, all these are saved to database for review, also it has variety of options to review the recorded information
We can use this tool to find and remove the performance bottlenecks to improve the performance of whole application, also its useful to understand the flow of others code quickly

Click Tools > Code profiler to open the Code Profiler tool.

  • Navigate to the functionality that you want to test
  • To limit the results displayed, check the Trace depth enabled check box, and then type the number of levels that you want to be displayed in the results.
  • Click Start.
  • Use the functionality you want to test.
  • When testing is complete, click Stop.
  • The system now saves all logged data to the database. This might take quite some time because a database record is created for each executed line of code.
  • Write a description of your code profile in the Summary dialog.
  • Click OK.
  • The Profiler runs form opens. This enables you to view data collected by the profiler 
  • You can control the code profiler directly from your X++ code. For this purpose there are two macros:
  1. #Profilebegin()
  2. #ProfileEnd
These two macros have to be in the same level in a method.


Go here to learn more about code profiler http://msdn.microsoft.com/en-US/library/aa847037.aspx
use Code Profiler programmatically http://msdn.microsoft.com/en-US/library/aa863679.aspx

Happy Daxing!!

Monday, 27 July 2015

AX 7 (Code Name Rainier) IDE

Interesting conversation on AX 7

https://community.dynamics.com/ax/f/33/t/151710

7 New Features Expected for Dynamics AX 7

Microsoft Dynamics AX is the premiere enterprise resource planning (ERP) package included in the Dynamics suite from Microsoft. The latest version of Microsoft Dynamics AX 7 (code named “Dynamics AX 7 Rainier”) has an expected release of late 2015.
Microsoft has been slowly leaking information about the new product, presenting the first live preview at Convergence 2015. While it is not yet known exactly the extent to which new features will be included in this upgrade, we can expect a big upgrade with exciting changes that will affect deployment, interfaces and possibly even licensing.
Here is a preview of "7 for 7" - 7 key features that are expected to appear in Dynamics AX 7:
1) Delivery through the Cloud
Microsoft has announced that Dynamics AX 7 is going to be a cloud-first application. This follows a trend that we have seen amongst other Microsoft flagship products. The latest update take full advantage of the Microsoft Azure cloud platform, Windows Server and the Microsoft Cloud OS. In fact, Microsoft has said that AX 7 2015 will initially launch on Azure only and won’t appear for on-premise deployments until 6 months later.
Moving Dynamics onto Azure and into the cloud provides a wider range of benefits. It will be easier to integrate the system with other cloud-based Microsoft products like Office 365. It also makes it easier to use Dynamics globally across multiple devices. Cloud deployment can also make Dynamics more accessible to businesses without an extensive information technology infrastructure.
2) A Focus on Mobile Access
It is also expected that Dynamics AX 7 is going to be available across a wide range of mobile devices, making it operational on nearly any modern smartphone or tablet. This becomes increasingly necessary as the business world becomes hooked on cloud and wants all operations and business data to be available at any time and from any location. Having access to real-time data from Dynamics through a mobile device will provide employees and business owners with better information to make informed decisions on the go, without having to get back to an office or a main workstation.
3) Best-in-Class Lifecycle Services Management
Expect to see best-in-class lifecycle services management with Dynamics AX 7. It is predicted that Microsoft is going to maintain and expand on the Lifecycle Services that are already in place. This type of management is available to anyone using the latest upgrade of Dynamics whether it is deployed on local systems or across the cloud. Best-in-class lifecycle services management means improving the reliability and quality of the Dynamics implementation used by any given business. It will also make rolling out new custom features less of a hassle. SaaSplaza is a member of the Microsoft LCS TAP program for AX7 and is providing technical input to match ourAX on Azure services with Microsoft LCS for the new AX version.
4) New Web-Based Client
Another change coming is that Dynamics AX 7 is will be accessible through a web-based client instead of a Windows desktop client. This means any shared in user will be able to access the Dynamics database through a basic web browser instead of needing to install customized applications on every system and device. Thus Web-based clients allow anyone in any location to access the different Dynamics modules. Having common web-based clients can improve productivity and facilitate business-wide collaboration on projects online regardless of location.
5) Streamlined HTML5 User Experience
The user experience in Dynamics AX 7 is based on the same framework used in Windows 8, and being improved upon in Windows 10. This interface uses the hypertext markup language version 5 (HTML 5) as a base. The HTML5 interface is designed to be lightweight and intuitive. It is context sensitive and the AX redesign is a dramatic departure from the normally bland windows and menus that have been found in previous versions of Dynamics AX. The new environment brings Dynamics in line with many other current Microsoft products. It will also make it easier to use Dynamics on mobile devices without a mouse or keyboard.
6) Incremental Updates Instead Of Version-ed Releases
Following the pattern that has been adopted by many other cloud-first software developers, Microsoft will end version-based releases of Dynamics similar to what was done with Office 365. Replacing the strict versioning system will be an approach based on the deployment platform. Each Dynamics platform will receive updates whenever necessary instead of re-releasing the entire software suite. This will make it easier to stay current since compatibility problems will no longer be an issue with incremental upgrades.
7) Subscription-Based Licensing
Another feature that is likely coming to Dynamics AX 7 is a more flexible licensing scheme based on subscriptions. The traditional Microsoft licensing model was sometimes cumbersome especially for businesses that had seasonal fluctuations in volume. Buying extra licenses that might never be used is impractical. The new model is more flexible allowing businesses to buy subscriptions to use Dynamics as needed and then cancel them later. Check out the current Microsoft Dynamics Subscription Licensing
More to Come!
The new features expected for Dynamics AX 7 is a look at the road-map into the future of Cloud-based ERP software. We are experiencing an explosion in changing technologies that take advantage of the cloud and mobile devices. It will be interesting to see how other companies stay-up-to date in their newest software releases. For now, stay tuned for more updates as we get closer to the Dynamics AX 7 release date.

Saturday, 18 July 2015

Customer Master AIF Service in AX

Dear All,

Today's am gonna share a code related to Customer Master Write operation.

In the sense inserting customers into AX thru the System Service.

Please follow the below steps as shown in screenshots.

1.Create Project in AOT and Add a Service Reference and Service Group Nodes into a created project as shown in below.

 2.Create a new Service Reference as below and add the inbuilt service class for the service.

3.For Customer master CRUD operation there is class in Ax named as "CustCustomerService".
select it in the property of a service reference and add the operation.
4.Once after adding the operation deploy the service and open VS.
5.In VS create new Windows Form Application Project and the URL to Service Reference as below.


5.Run the below code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CustomerMasterMasterWriteTest.CustomerCreate;

namespace CustomerMasterMasterWriteTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            CustomerCreate.CustomerMasterWriteClient proxy = new CustomerCreate.CustomerMasterWriteClient();
            //CustomerCreate.CustomerMasterCreateServiceClient proxy = new CustomerCreate.CustomerMasterCreateServiceClient();
            CustomerCreate.CallContext newcont = new CustomerCreate.CallContext();
            newcont.Company = "mub";
            CustomerCreate.AxdCustomer customer = new CustomerCreate.AxdCustomer();
            CustomerCreate.AxdEntity_CustTable Custtable = new CustomerCreate.AxdEntity_CustTable();
            Custtable.AccountNum = "998877";
            Custtable.Currency = "USD";
            Custtable.CustGroup = "20";
            Custtable.OneTimeCustomer = CustomerCreate.AxdExtType_OneTimeCustomer.Yes;
            Custtable.OneTimeCustomerSpecified = true;

            //Create the party record
            CustomerCreate.AxdEntity_DirParty_DirPerson party = new CustomerCreate.AxdEntity_DirParty_DirPerson();
            party.NameAlias = "TestInsertion";

            //Set the name fields
            CustomerCreate.AxdEntity_PersonName personName = new CustomerCreate.AxdEntity_PersonName();
            personName.FirstName = "Test";
            personName.MiddleName = "Tester";
            personName.LastName = "Newell";

            //Add the names to the party record and set the name sequence

            party.PersonName = new CustomerCreate.AxdEntity_PersonName[1] { personName };
            party.NameSequence = "FirstLast";

            //Create a postal address
            CustomerCreate.AxdEntity_DirPartyPostalAddressView address = new CustomerCreate.AxdEntity_DirPartyPostalAddressView();
            address.LocationName = "Location Name";
            address.Street = "2122 NE 5th St";
            address.City = "Beverly Hills";
            address.State = "CA";
            address.CountryRegionId = "USA";
            address.ZipCode = "90210";
            address.Roles = "Home;Delivery";

            //Create an electronic address
            CustomerCreate.AxdEntity_DirPartyContactInfoView electronicAddress = new CustomerCreate.AxdEntity_DirPartyContactInfoView();
            electronicAddress.LocationName = "Contact Email";
            electronicAddress.Type = CustomerCreate.AxdEnum_LogisticsElectronicAddressMethodType.Email;
            electronicAddress.TypeSpecified = true;
            electronicAddress.Locator = "beckynewell@madeup.com";
            electronicAddress.Roles = "Home";

            //Add the addresses to the party record and the party to the CustTable record
            Custtable.DirParty = new CustomerCreate.AxdEntity_DirParty_DirPartyTable[1] { party };
            Custtable.DirParty[0].DirPartyPostalAddressView = new CustomerCreate.AxdEntity_DirPartyPostalAddressView[1] { address };
            Custtable.DirParty[0].DirPartyContactInfoView = new CustomerCreate.AxdEntity_DirPartyContactInfoView[1] { electronicAddress }; ;

            //Add the CustTable record to the Customer entity
            customer.CustTable = new CustomerCreate.AxdEntity_CustTable[1] { Custtable };
            //Create the customer
            proxy.create(newcont, customer);
        }
    }
}