Loading ...

Using Web Methods in Acumatica and Calling Them with AJAX from an ASPX Page

One of the ways to interact with server-side code is through web methods, which can be invoked asynchronously using AJAX (Asynchronous JavaScript and XML) from client-side scripts. This article will guide you through creating web methods in Acumatica and calling them using AJAX from an ASPX page.

Setting Up the ASPX Page with Master Pages

At the top of your ASPX page, include the following directives to specify the master page and its type:

<%@ Page Language="C#" MasterPageFile="~/MasterPages/FormView.master" AutoEventWireup="true" ValidateRequest="false" CodeFile="ACPR3000.aspx.cs" Inherits="Page_ACPR3000" Title="Untitled Page" %>

<%@ MasterType VirtualPath="~/MasterPages/FormView.master" %>

With this master page, you can add the following section where we can include custom styles and scripts:

Additionally, EnablePageMethods should be enabled:

Creating a Web Method in Acumatica 

In Acumatica, web methods are public static methods defined in the code-behind of an ASPX page or a user control. They are decorated with the [WebMethod] attribute, which makes them accessible for AJAX calls. 

Example: Defining a Web Method 

Below is an example of a web method that retrieves tasks based on a project code:

Key Points: 

  1. The method is public and static. 

  2. It is decorated with the [WebMethod] attribute. 

  3. Parameters can be passed to the method (e.g., string projectCD). 

  4. The method returns data that can be serialized to JSON.

Calling the Web Method Using AJAX 

To invoke the web method from the client side, you can use AJAX. jQuery simplifies AJAX calls and is widely used in web applications. 

Including jQuery 

Ensure that jQuery is included in your page, as shown before. You can use the CDN link or host it locally. 

Writing the AJAX Function

Be the first to rate this post

  • Currently 0.0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5