Search code examples
microsoft-dynamicsnavisiondynamics-navdynamics-business-centraldynamics-al

How to debug web service calls in Business Central?


According to the Microsoft Documentation...

I'm trying to debug my API:

enter image description here

The page code is just here, a copy of the standard customers api

I've only modified the OnAfterGetRecord() trigger with this code:

trigger OnAfterGetRecord()
begin
    SetCalculatedFields();

    if newNumber <> '' then
        Rec."No." := newNumber;
end;

Also added few fields:

field(PartnerType; Rec."Partner Type")
{
    Caption = 'Partner Type';

    trigger OnValidate()
    begin
        RegisterFieldSet(Rec.FieldNo("Partner Type"));
    end;
}
field(CombineShipments; Rec."Combine Shipments")
{
    Caption = 'Combine Shipments';

    trigger OnValidate()
    begin
        RegisterFieldSet(Rec.FieldNo("Combine Shipments"));
    end;
}
field(newNumber; newNumber)
{
    Caption = 'New No. (custom field)';
}

This is my launch.json:

{
    "name": "Attach: Web Services",
    "type": "al",
    "request": "attach",
    "environmentType": "Sandbox",
    "environmentName": "sandbox",
    "breakOnError": "All",
    "breakOnRecordWrite": "None",
    "enableSqlInformationDebugger": true,
    "enableLongRunningSqlStatements": true,
    "longRunningSqlStatementsThreshold": 500,
    "numberOfSqlStatements": 10,
    "breakOnNext": "WebServiceClient"
}

I POST with Postman and debugger doesn't break:

enter image description here

So, I can't debug my error... How can I debug and step into my breakpoints?


Solution

  • After having a lot of problems for not being able to debug web services long time, I've found what I was missing!

    You must specify the Microsoft Entra user (OAUTH User) in your launch.json:

    "userId": "CUSTOM API"
    

    You can find it here:

    enter image description here

    The debugger worked instantly:

    enter image description here

    I am now succesfully debugging web service calls 😀