Monday, 24 February 2020

How to call external class method in enterprise portal

Today, I will be discussing about how to call external class method in enterprise portal.
There was a requirement in which we need to update some information on updating the vendor account within purchase requisition web page on enterprise portal.

For changing this target i created a new class and added a static method inside it. This class was created with in AX and names as PRTestHelper class.

Class: PRTestHelper
Static Method : updateVendorAccount

Now we need to add override the ondatachanged method of vendor account field in PurchReqLineInfo_ascx_cs. Add following code in the class.

 protected void VendAccount_DataChanged(object sender, AxBoundFieldDataChangedEventArgs e)
{
        this.setupDefaultDimension(true);
       
       
        if (Page.IsPostBack)
        {
            Page.Validate();
            if (Page.IsValid)
            {
                DataSetViewRow row;

                row = this.PurchReqLineDS.GetDataSet().DataSetViews["PurchReqLine"].GetCurrent();
                this.AxSession.AxaptaAdapter.CallStaticClassMethod("PRTestHelper", "updateVendorAccount", row.GetFieldValue("RecId"), row.GetFieldValue("VendAccount"));
                DialogHelper.Close(CloseDialogBehavior.RefreshPage);
            }
        }
       
   }


// Following code is used to call method :  this.AxSession.AxaptaAdapter.CallStaticClassMethod("PRTestHelper", "updateVendorAccount", row.GetFieldValue("RecId"), row.GetFieldValue("VendAccount"));

First parameter is : Class name
Second parameter is : Method name
Third parameter is : RecId of Purchase Requisition line
Fourth parameter is : Vendor account

Note : 3rd and 4th parameter are optional as we are using them to send parameter to static method.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Custom Business events Part 3 - (Activate custom business event) in D365 F&O

 In this blog we will discuss about the steps to activate a custom business in D365 F&O. As we know that business event catalog does not...