Calling Ax methods in C# and EP

HI,

Below are the sample codes to call the methods of X++ in C# from EP development,

//calling the modified method of the control in EP

public void getstartdate(object sender, EventArgs e)

{

string sdateAx;

sdateAx = (string)this.AxDataSource1.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call(“modified”);    }

This method should be written under particular field in Data set in AOT. For that field only we need to assign this method in C# control. And put ‘Autopostback’ TRUE.

call this method on C# control : Onlookup = “getstartdate”.

//Calling static methods.

We can call the static methods in C# which are written at Table or at Class level only.

In below example, we are calling a static method which is written in table ‘Mzk_LeaveHistory’ table and the method name in ‘currentEmployeeId’. And we are catching the value which the method is returning for the validations in C#. Since we can’t do validations by using the code in X++.

Here, based on the login employee we need to validate the leave balance and validation.

public void LeaveBalanceValidation(object sender, AxBoundFieldDataChangedEventArgs e)

{

Int64 EmplId = (Int64)AxSession.AxaptaAdapter.CallStaticRecordMethod(“Mzk_LeaveHistory”, “currentEmployeeId”);

//Response.Write(EmplId);

string LeavetypeBalance = Convert.ToString(e.Value);

//string Leavetypevalidate = Convert.ToString(DropDownList)e.BoundControl).SelectedValue);

string Leavetypevalidate = Convert.ToString(e.Value);

this.LeaveValidation(Leavetypevalidate, EmplId);

this.LeaveBalance(LeavetypeBalance, EmplId);

//  this.AxDataSource1.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call(“modified”);

}

Need to call in controller in C# :  OnDataChanged = “LeaveBalanceValidation”

Leave Balance can come on the leave type they selected, we are calling a static method in the table by passing the employee id and leave type selected.

For more description, plebe fallow below link:

http://msdn.microsoft.com/en-us/library/ee677497.aspx

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s