BeamerEA
BeamerEA

Reputation: 113

Post data to custom AL field in Business Central

I am trying to create an API call to add data into a custom field that was created on the Sales Order page using AL Extensions. The issue is when I try to do the api call through postman, I am getting "The Property "propertyName" does not exist on type 'Microsoft.NAV.salesOrder'". First of all, I don't even know if the API allows for this, so is it even possible? And secondly, if it is possible, is there a certain way to set up the API call or the Field through the AL Extension?

tableextension 50100 "AddProjectIdToSalesOrder" extends "Sales Header"
{
    fields
    {
        field(50100; "CrmProjectId"; Guid)
        {
            Caption = 'Crm Project Id';
            DataClassification = OrganizationIdentifiableInformation;
        }
    }
}

pageextension 50100 "AddProjectIdToSalesOrder" extends "Sales Order"
{
    layout
    {
        addlast(General)
        {
            field("CRM Project Id"; Rec.CrmProjectId)
            {
                ApplicationArea = all;
                ToolTip = 'The Guid of the related Project Record in the CRM environment';
            }
        }
    }
}

This is how I am setting up the field with the AL extension, and for the post call, I am just creating a new Sales Order with a post and the body looks like:

{
    "customerNumber" : "10000",
    "CrmProjectId" : "random-guid"
}

And the error is "Bad Request": "The property 'CrmProjectId' does not exist on type 'Microsoft.NAV.salesOrder'. Make sure to only use property names that are defined by the type." Any help would be appreciated.

Upvotes: 4

Views: 980

Answers (1)

kaspermoerch
kaspermoerch

Reputation: 16560

The Sales Order API is a separate page. It is not equivalent to the Sales Order page so you have to modify the API to accomplish what you want.

However the standard API's provided by Microsoft can't be extended.

You are left with two options:

  • Make a copy of the standard Sales Order API (this involves making a copy of all the linked APIs as well e.g. the Sales Line API).
  • Create a new API page with the single purpose of updating your new field. Then you would use the standard Sales Order API to create the Sales Order and then update CrmProjectId with a second call to your custom API page.

Upvotes: 1

Related Questions