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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

How to return Json using unbound action api in business central

(2) ShareShare
ReportReport
Posted on by 39
I need to create API which inserts and updates data, both using POST Request where I need to check if the record already exists to modify it otherwise will insert new record.
I tried this using page API and it works well but the response is empty for unspecified fields 

for example :
This is the response of GET Request 
{
 
            /Primary_Key/: /218000_0104003/,
            /Group_Account/: /218000/,
            /Group_Account_Name/: /Other tangible assets/,
            /Analytical_Account_No_/: /0104003/,
            /Analytical_Account_Name/: /T&M ASSISTANCE/,
            /Group_Blocked/: true,
            /Blocked/: false,
            /Analytical_Blocked/: false
        }
 
 
when I try to modify the Group_blocked , I need to send Primary key and group_Blocked in the request body and expect the whole record as response 
 
{
    /Primary_Key/: /218000_0104003/,
    /Group_Blocked/: false
 
}
 
I get this response
 
{
 
    /Primary_Key/: /218000_0104003/,
    /Group_Account/: //,
    /Group_Account_Name/: //,
    /Analytical_Account_No_/: //,
    /Analytical_Account_Name/: //,
    /Group_Blocked/: false,
    /Blocked/: false,
    /Analytical_Blocked/: false
}

This is the code 
 
page 71172 /XEE_Analytical_Account/
{
    PageType = API;
    Caption = 'Analytical Accounts';
    APIPublisher = 'XEETEK';
    APIGroup = 'Payroll';
    APIVersion = 'v2.0';
    EntityName = 'AnalyticalAccount';
    EntitySetName = 'AnalyticalAccounts';
    SourceTable = /XEE Group-Analytical Account/;
    DelayedInsert = true;
    ODataKeyFields = /Primary Key/;
    // DataAccessIntent = ReadWrite;
    // Editable = false;
    ModifyAllowed = true;
    InsertAllowed = true;
    layout
    {
        area(Content)
        {
            repeater(GroupName)
            {
                field(/Primary_Key/; rec./Primary Key/)
                {
                    Caption = 'ID';
                    ApplicationArea = all;
                    trigger OnValidate()
                    var
                    begin
                        RegisterFieldSet(rec.FieldNo(/Primary Key/));
                    end;
                }
                field(/Group_Account/; rec./Group Account/)
                {
                    ApplicationArea = all;
                    trigger OnValidate()
                    var
                    begin
                        RegisterFieldSet(rec.FieldNo(/Group Account/));
                    end;
                }
                field(/Group_Account_Name/; rec./Group Account Name/)
                {
                    ApplicationArea = all;
                    trigger OnValidate()
                    var
                    begin
                        RegisterFieldSet(rec.FieldNo(/Group Account Name/));
                    end;
                }
                field(/Analytical_Account_No_/; rec./Analytical Account No./)
                {
                    ApplicationArea = all;
                    trigger OnValidate()
                    var
                    begin
                        RegisterFieldSet(rec.FieldNo(/Analytical Account No./));
                    end;
                }
                field(/Analytical_Account_Name/; rec./Analytical Account Name/)
                {
                    ApplicationArea = all;
                    trigger OnValidate()
                    var
                    begin
                        RegisterFieldSet(rec.FieldNo(/Analytical Account Name/));
                    end;
                }
                field(/Group_Blocked/; rec./Group Blocked/)
                {
                    ApplicationArea = all;
                    trigger OnValidate()
                    var
                    begin
                        RegisterFieldSet(rec.FieldNo(/Group Blocked/));
                    end;
                }
                field(Blocked; rec.Blocked)
                {
                    ApplicationArea = all;
                    trigger OnValidate()
                    var
                    begin
                        RegisterFieldSet(rec.FieldNo(Blocked));
                    end;
                }
                field(/Analytical_Blocked/; rec./Analytical Blocked/)
                {
                    ApplicationArea = all;
                    trigger OnValidate()
                    var
                    begin
                        RegisterFieldSet(rec.FieldNo(/Analytical Blocked/));
                    end;
                }
            }
        }
    }
    trigger OnInsertRecord(Xrec: Boolean): Boolean
    var
        GropAna: Record /XEE Group-Analytical Account/;
    begin
        GropAna.SetRange(/Primary Key/, rec./Primary Key/);
        if GropAna.FindFirst() then begin
            if TempFieldSet.Get(Database::/XEE Group-Analytical Account/, Rec.FieldNo(Blocked)) then
                GropAna.Blocked := rec.Blocked;
            if TempFieldSet.Get(Database::/XEE Group-Analytical Account/, Rec.FieldNo(/Group Blocked/)) then
                GropAna./Group Blocked/ := rec./Group Blocked/;
            if TempFieldSet.Get(Database::/XEE Group-Analytical Account/, Rec.FieldNo(/Analytical Blocked/)) then
                GropAna./Analytical Blocked/ := rec./Analytical Blocked/;
            GropAna./Analytical Account No./ := GropAna./Analytical Account No./;
            GropAna./Analytical Account Name/ := GropAna./Analytical Account Name/;
            GropAna./Group Account/ := GropAna./Group Account/;
            GropAna./Group Account Name/ := GropAna./Group Account Name/;
            GropAna.Modify();
        end
        else begin
            if (rec./Analytical Account No./ = '') and (rec./Group Account/ = '') then
                Error('There should be at least one account');
            rec.Insert(true);
        end;
        exit(false);
    end;
    var
        TempFieldSet: Record 2000000041 temporary;

    local procedure RegisterFieldSet(FieldNo: Integer)
    begin
        if TempFieldSet.Get(Database::/XEE Group-Analytical Account/, FieldNo) then
            exit;
        TempFieldSet.Init();
        TempFieldSet.TableNo := Database::/XEE Group-Analytical Account/;
        TempFieldSet.Validate(/No./, FieldNo);
        TempFieldSet.Insert(true);
    end;
}
 
Is There any error in this code or any other way to send the record in response
Note: I dont want to send patch request, I want update and insert using POST request 
I have the same question (1)
  • Suggested answer
    YUN ZHU Profile Picture
    98,062 Super User 2026 Season 1 on at

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

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 2,091 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,032 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 946 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans