web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

API Batch request for Post Method in Business Central

(1) ShareShare
ReportReport
Posted on by
here is Api page, I want to post, delete and modify batch entries using single api and don't want to use any filter with Api. I have entry no as primary key in table but CRM has "lead id" as primary key. tell me what the payload can be and how can implement the logic for batch insertion, deletion and updating
page
80002 "ABCAPIs"
{
    APIGroup = 'ABCPortal';
    APIPublisher = 'ABCPublisher';
    APIVersion = 'v2.0';
    ApplicationArea = All;
    Caption = 'ABCAPI';
    DelayedInsert = true;
    EntityName = 'sdSchedules';
    EntitySetName = 'sdScheduless';
    PageType = API;
    SourceTable = "SD Schedule";
    ODataKeyFields = "Entry No";
 
    layout
    {
        area(Content)
        {
            repeater(General)
            {
                field(entryNo; Rec."Entry No")
                {
                    Caption = 'Entry No';
                }
                field("proposalId"; Rec."Lead Id")
                {
                    Caption = 'Proposal Id';
                }
                field(sdMonths; Rec."SD Months")
                {
                    Caption = 'SD Months';
                }
                field(sdDueDate; Rec."SD Due Date")
                {
                    Caption = 'SD Due Date';
                }
                field(totalSDAmount; Rec."Total SD Amount")
                {
                    Caption = 'Total SD Amount';
                }
            }
        }
    }
 
    // actions
    // {
    //     area(Processing)
    //     {
    // action(BatchCreate)
    // {
    //     ApplicationArea = All;
    //     Caption = 'BatchCreateSDSchedules';
    //     ToolTip = 'Batch create SD schedules';
 
    // }
    // }
    // }
 
    // [ServiceEnabled]
    // procedure PostBatchSDSchedules(var ActionContext: WebServiceActionContext; ContentCtrl: Text): Text
    // var
    //     BatchService: Codeunit "SDSchedule Batch Services";
    // begin
    //     exit(BatchService.BatchCreateSDSchedules(ActionContext, ContentCtrl));
    // end;
 
    trigger OnInsertRecord(BelowxRec: Boolean): Boolean
 
    begin
        CustRec.SetRange("Lead Id", Rec."Lead Id");
        if CustRec.FindFirst() then begin
            Rec."SD Id" := CustRec."No.";
            exit(true);
        end;
 
        // SDSchedule.SetRange("Entry No", Rec."Entry No");
        // if SDSchedule.FindFirst() then begin
        //     SDSchedule."SD Due Date" := Rec."SD Due Date";
        //     SDSchedule."SD Months" := Rec."SD Months";
        //     SDSchedule."Total SD Amount" := Rec."Total SD Amount";
        //     SDSchedule.Modify(true);
        //     exit(false);
        // end;
        // exit(true);
        SDSchedule.SetRange("Lead Id", Rec."Lead Id");
        if SDSchedule.FindSet() then begin
            repeat
                SDSchedule."SD Due Date" := Rec."SD Due Date";
                SDSchedule."SD Months" := Rec."SD Months";
                SDSchedule."Total SD Amount" := Rec."Total SD Amount";
                SDSchedule.Modify(true);
                exit(false);
            until SDSchedule.Next() = 0;
        end;
        exit(true);
    end;
 
    trigger OnModifyRecord(): Boolean
    begin
        SDSchedule.SetRange("Lead Id", Rec."Lead Id");
        if SDSchedule.FindSet() then begin
            repeat
                SDSchedule."SD Due Date" := Rec."SD Due Date";
                SDSchedule."SD Months" := Rec."SD Months";
                SDSchedule."Total SD Amount" := Rec."Total SD Amount";
                SDSchedule.Modify(true);
                exit(true);
            until SDSchedule.Next() = 0;
            exit(false);
        end;
    end;
 
    trigger OnDeleteRecord(): Boolean
    begin
        SDSchedule.SetRange("Lead Id", Rec."Lead Id");
        if SDSchedule.FindSet() then begin
            repeat
                SDSchedule."SD Due Date" := Rec."SD Due Date";
                SDSchedule."SD Months" := Rec."SD Months";
                SDSchedule."Total SD Amount" := Rec."Total SD Amount";
                SDSchedule.Delete(true);
                exit(false);
            until SDSchedule.Next() = 0;
        end;
        exit(true);
    end;
 
    var
        SDSchedule: Record "SD Schedule";
        CustRec: Record Customer;
}
I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    96,648 Super User 2025 Season 2 on at
    Hi, hope the following can give you some hints.
     
    Thanks.
    ZHU

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,845

#2
YUN ZHU Profile Picture

YUN ZHU 863 Super User 2025 Season 2

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 809

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans