microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
745 stars 244 forks source link

Bug in extending Page API for InvoiceSalesLine #5477

Closed Farzad-Jalali closed 4 years ago

Farzad-Jalali commented 4 years ago

I extended the "sales invoice line" page as API PAGE, now I try to "Get" the same line with my extended API page and as well as the original API (which is available out of the box with fewer fields exposed)

Version: I got the latest AL extension in visual studio code I'm using the cloud business central (sandbox)

something like this:

api/v1.0/companies(0a98558c-fbce-4215-adac-3e1c6c698bd1)/salesInvoices(58fa88d9-a00b-ea11-a814-000d3a86d630)/salesInvoiceLines

I'm getting the below response

"value": [
        {
            "@odata.etag": "W/\"JzQ0O1RxdFZwemF5N0VHbk9zT012eXNVTkVjU2VTYXhDK0x4VUlyaThPdEszU1k9MTswMDsn\"",
            "id": "58fa88d9-a00b-ea11-a814-000d3a86d630-10000",
            "documentId": "58fa88d9-a00b-ea11-a814-000d3a86d630",
            "sequence": 10000,
            "itemId": "32aeb57f-0c0a-ea11-a813-000d3a86dee3",
            "accountId": "00000000-0000-0000-0000-000000000000",
            "lineType": "Item",
            "description": "BLA 12X150",
            "unitOfMeasureId": "08c17630-c2df-e911-bb47-000d3a2be95d",
            "unitPrice": 9.53,
            "quantity": 47,
            "discountAmount": 0,
            "discountPercent": 0,
            "discountAppliedBeforeTax": false,
            "amountExcludingTax": 447.91,
            "taxCode": "ZERO",
            "taxPercent": 0,
            "totalTaxAmount": 0,
            "amountIncludingTax": 447.91,
            "invoiceDiscountAllocation": 0,
            "netAmount": 447.91,
            "netTaxAmount": 0,
            "netAmountIncludingTax": 447.91,
            "shipmentDate": "2019-11-20",
            "lineDetails": {
                "number": "20001132",
                "displayName": "BLA 12X150"
            },
            "unitOfMeasure": {
                "code": "BOX",
                "displayName": "Box",
                "symbol": null,
                "unitConversion": null
            }
        }

api/bwg/apigroup1/beta/companies(0a98558c-fbce-4215-adac-3e1c6c698bd1)/SalesInvoiceLine(58fa88d9-a00b-ea11-a814-000d3a86d630-10000)

the result is: {"error":{"code":"BadRequest_NotFound","message":"')' or ',' expected at position 4 in '(58fa88d9-a00b-ea11-a814-000d3a86d630-10000)'. CorrelationId: a0b0d992-1329-46ae-afbf-2bd5bcf56065."}}

here is my code:


page 50110 "Sales Invoice Line BWG"
{
    PageType = API;
    Caption = 'Sales Invoice Line BWG';
    APIPublisher = 'bwg';
    APIGroup = 'apigroup1';
    APIVersion = 'beta';
    EntityName = 'SalesInvoiceLine';
    EntitySetName = 'SalesInvoiceLine';
    SourceTable = "Sales Invoice Line";
    DelayedInsert = true;
    ODataKeyFields = SystemId;

    layout
    {
        area(Content)
        {
            repeater(GroupName)
            {

                // ###################################
                field(SystemId; SystemId)
                {
                    Caption = 'SystemId';
                    ApplicationArea = All;
                }

            }

            field("DimensionSetID"; "Dimension Set ID")
            {
                Caption = 'DimensionSetID';
                ApplicationArea = All;
            }
            field("DocumentNo"; "Document No.")
            {
                Caption = 'DocumentNo';
                ApplicationArea = All;
            }
            field(Description; Description)
            {
                Caption = 'Description';
                ApplicationArea = All;
            }
            field("LineNo"; "Line No.")
            {
                Caption = 'LineNo';
                ApplicationArea = All;
            }
            field("No"; "No.")
            {
                Caption = 'No';
                ApplicationArea = All;
            }
            field("ShortcutDimension1Code"; "Shortcut Dimension 1 Code")
            {
                Caption = 'ShortcutDimension1Code';
                ApplicationArea = All;
            }
            field("ShortcutDimension2Code"; "Shortcut Dimension 2 Code")
            {
                Caption = 'ShortcutDimension2Code';
                ApplicationArea = All;
            }
            // ######################################
        }
    }

    trigger OnInsertRecord(BelowxRec: Boolean): Boolean
    begin
        Insert(true);

        Modify(true);
        exit(false);
    end;

    trigger OnModifyRecord(): Boolean
    var
        theRow: Record Item;
    begin
        theRow.SETRANGE(SystemId, SystemId);
        theRow.FINDFIRST;

        // any business logic here
    end;

    trigger OnDeleteRecord(): Boolean
    begin
        Delete(true);
        exit(false);
    end;
}
PhDuck commented 4 years ago

Hey @Farzad-Jalali I just tested with your page locally and it works perfectly fine:

image

I would guess the reason why it isn't working for you is because the UUID you are passing as an argument is not a correct UUID.

Notice your UUID vs mine. 58fa88d9-a00b-ea11-a814-000d3a86d630-10000 9e38cbd3-e33d-ea11-bb33-000d3a3a5879

PhDuck commented 4 years ago

Ohh also another thing, you can simplify your code by doing the following:

    trigger OnModifyRecord(): Boolean
    var
        theRow: Record Item;
    begin
        theRow.GetBySystemId(SystemId);

        // any business logic here
    end;

See documentation here: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/record/record-getbysystemid-method

PooyaKharamesh commented 4 years ago

I am closing this issue because it appears that it has been resolved. Please open a new issue if you believe this has not been resolved and reference the current issue.