【问题标题】:Business Central API Extension: How do I connect insert trigger to API Custom Page?Business Central API 扩展:如何将插入触发器连接到 API 自定义页面?
【发布时间】:2020-10-09 19:34:32
【问题描述】:

我创建了一种新的页面类型的 API,它使用销售发票标头源。我想获取新插入的记录并更新其值。之后在警报中显示该值。目前我在创建新的销售发票后有一个空白页面。

这是我的代码:

page 50105 "Custom Invoice API" {
    PageType = API;
    Caption = 'Custom Sales Invoice Header API';
    APIPublisher = 'xy';
    APIVersion = 'beta';
    APIGroup = 'customsalesinvoiceheader';
    EntityName = 'salesInvoiceHeader';
    EntitySetName = 'salesInvoiceHeaders';
    SourceTable = "Sales Invoice Header";
    DelayedInsert = true;


    layout
    {
        area(Content)
        {
            repeater(GroupName)
            {
                field(id; "No.")
                {
                    Caption = 'No.';
                }
                field(name; "Sell-to Customer Name")
                {
                    Caption = 'Customer Name';
                }
                field(address; "Sell-to Address")
                {
                    Caption = 'Sell-to Adress';
                }
                field(shipdate; "Shipment Date")
                {
                    Caption = 'Shipment Date';
                }
            }
        }
    }
    trigger OnInsertRecord(BelowxRec: Boolean): Boolean
    begin
        Insert(true);
        Message(readInvoice());
        updateInvoice();
        exit(true);
    end;

    procedure readInvoice(): Text
    var
        currentInvoice: Record "Sales Invoice Header";
    begin
        exit(currentInvoice."No." + ' ' + currentInvoice."Sell-to Customer Name" + ' ' + currentInvoice."Sell-to Address" + ' ' + Format(currentInvoice."Shipment Date"));
    end;

    procedure updateInvoice()
    var
        currentInvoice: Record "Sales Invoice Header";
    begin
        currentInvoice."Shipment Date" := DMY2Date(19, 6, 2020);
    end; 
}

之后,我在我的 BC 类型查询中创建了一个新的 Web 服务,该服务以销售发票为目标,但在邮递员中我得到 401,无论我是对我的管理员用户使用基本身份验证还是在我的管理员用户上生成的 Web 服务应用程序密钥.

如何将插入触发器操作连接到我的 API 自定义页面?

【问题讨论】:

    标签: dynamics-business-central dynamics-al


    【解决方案1】:

    你的策略有一些问题,我会在这里列出:

    关于 401 错误,很大程度上取决于您使用的是公共云 BC(由 MS 托管)还是本地托管/OnPrem 配置。

    【讨论】:

    • 我正在使用云 BC。
    • 检查此答案:“转到扩展管理,选择您的扩展,然后从管理菜单中选择配置。在配置页面中,将 AllowHttpCleintRequest 设置为 True。” stackoverflow.com/questions/60153873/…你可能忘记给你的扩展 HttpClient 授权了。
    猜你喜欢
    • 2020-10-22
    • 2021-01-02
    • 1970-01-01
    • 2022-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    • 2023-01-17
    相关资源
    最近更新 更多