You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何通过代码复现采购收货单页面添加已审批采购订单的操作

Replicating the "ADD PO" Smart Panel Action via Code

Got it, let's break down how to replicate that "ADD PO" button functionality in code—since you already have your approved Normal PO visible in the smart panel, the core goal is to mimic the backend logic that runs when you click that UI button.

Step 1: Identify the Backend Logic from ASPX

First, dig into the ASPX definition of the purchase receipt page to find what the "ADD PO" button is triggering. Look for attributes like CommandName or OnClick on the button control. For example, you might see something like:

<px:PXButton runat="server" ID="btnAddPO" CommandName="AddPO" Text="ADD PO" />

This tells you the backend command/method name to target (in this case, AddPO). Next, check the code-behind or the associated business graph class (common in ERP systems like Acumatica) to see how this command is implemented.

Step 2: Code Implementation Example

Below is a typical code pattern to replicate the UI action. This example assumes you're working with an ERP system that uses business graphs (adjust based on your specific platform):

// 1. Instantiate the purchase receipt business graph
POReceiptEntry receiptGraph = PXGraph.CreateInstance<POReceiptEntry>();

// 2. Create a new purchase receipt header (if starting from scratch)
POReceipt newReceipt = receiptGraph.Receipts.Insert(new POReceipt());

// 3. Fetch your approved Normal PO (replace with your PO type/number)
POOrder targetPO = PXSelect<POOrder, 
    Where<POOrder.orderType, Equal<Required<POOrder.orderType>>,
        And<POOrder.orderNbr, Equal<Required<POOrder.orderNbr>>>>>
    .Select(receiptGraph, "NORMAL", "PO-00123");

// 4. Mimic selecting the PO in the smart panel and triggering the ADD action
// First, add the PO to the selected items collection (matches UI selection)
receiptGraph.SelectedPOs.Select(targetPO);
// Trigger the AddPO command (matches clicking the button)
receiptGraph.AddPO.Press();

// 5. Save the generated purchase receipt
receiptGraph.Actions.PressSave();

Key Notes to Ensure Success

  • PO Status Check: Verify your PO is in an approved state (the same state that makes it visible in the UI smart panel)—most systems won't allow adding unapproved POs to receipts.
  • Permission Validation: Make sure the code runs under a user context with sufficient permissions to create receipts and link POs.
  • Debug the UI Flow: If you're unsure about the exact backend calls, set a breakpoint in the AddPO method (found via the ASPX command name) while clicking the UI button. This will show you the full execution chain, including any validations or pre-processing steps you need to replicate.
  • Adjust for Your System: If your platform uses a different pattern (e.g., web service calls instead of business graphs), adapt the code to call the corresponding API endpoint that handles PO-to-receipt linking.

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

火山引擎 最新活动