You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Acumatica中Hello World按钮无预期响应问题求助

Acumatica AR303000页面按钮回调未触发服务器端代码排查

在AR303000(客户界面)添加Hello World按钮后,点击触发回调返回0|<ctl00_phF_BAccount_t0_btnHelloWorld />,未执行预期的服务器端报错逻辑,怀疑服务器代码未触发。以下是问题代码及排查修复建议:

问题代码

AR303000页面ASPX代码

<px:PXFormView ID="BAccount" runat="server" Width="100%" Caption="Customer Summary" DataMember="BAccount" NoteIndicator="True" FilesIndicator="True" ActivityIndicator="false" ActivityField="NoteActivity" LinkIndicator="true" BPEventsIndicator="true" DefaultControlID="edAcctCD">
<Template>
  <px:PXLayoutRule runat="server" StartColumn="True" ControlSize="XM" LabelsWidth="SM" ></px:PXLayoutRule>
    <px:PXButton runat="server" Text="Hello World" AutoCallBack="True" ID="btnHelloWorld">
 <AutoCallBack Command="HelloWorld" /></px:PXButton>
 <px:PXSegmentMask ID="edAcctCD" runat="server" DataField="AcctCD" FilterByAllFields="True" ></px:PXSegmentMask>
 <px:PXDropDown ID="edStatus" runat="server" DataField="Status" CommitChanges="True" ></px:PXDropDown>

定制项目C#代码

using PX.Data;
using PX.Objects.AR; // for CustomerMaint graph
using PX.Objects.CR; // for BAccount DAC

public class CustomerMaint_Extension : PXGraphExtension<CustomerMaint>
{
    // Define the action matching the button we will create
    public PXAction<BAccount> HelloWorld;

    [PXButton] // Indicates this is a button action
    [PXUIField(DisplayName = "Hello World")] // Label for the button/action
    protected void helloWorld()
    {
        // If this code runs, it will throw an exception and show a popup error in the UI.
        throw new PXException("Hello world from the server!");
    }
}

排查与修复建议

  • 修正Action与方法的绑定:原C#代码仅声明了HelloWorld Action字段,但未将其绑定到helloWorld()方法,这是核心问题。Acumatica无法识别未绑定的Action,导致回调无响应。修正方式有两种:

    1. 在Initialize方法中绑定:
      protected override void Initialize()
      {
          base.Initialize();
          HelloWorld = delegate { helloWorld(); };
      }
      
    2. 字段声明时直接赋值委托:
      public PXAction<BAccount> HelloWorld = delegate (PXAdapter adapter) 
      { 
          helloWorld(); 
          return adapter.Get(); 
      };
      
  • 验证Action名称匹配:确保ASPX中AutoCallBack Command="HelloWorld"与C#中Action字段名HelloWorld完全一致(大小写敏感)。

  • 确认定制项目状态:检查包含该扩展的定制项目已发布至目标Acumatica实例,且在**SM204500(定制项目)**页面中处于激活状态。

  • 调试日志验证执行:在helloWorld()方法中添加日志输出,通过**SM202010(系统日志)**查看是否有记录,确认代码是否执行:

    PXLogger.LogInfo("HelloWorld action triggered on server");
    
  • 检查回调目标:若PXFormView存在多个DataMember,需为按钮的AutoCallBack指定Target属性,确保回调指向正确的Graph容器:

    <AutoCallBack Command="HelloWorld" Target="BAccount" />
    
  • 浏览器网络请求排查:点击按钮时,打开浏览器开发者工具的Network面板,查看回调请求的参数是否包含command=HelloWorld,以及服务器返回的完整响应内容,排查是否有隐藏错误。

内容的提问来源于stack exchange,提问作者EglCode

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 15:13:17