问题描述
我的问题是我无法为特定的itemId
调用我的自定义API,但是当我调用普通API时,它可以按预期工作。
目前,我可以成功调用特定项目的常规API,如下所示:
myBcServer:Port/bc/api/v1.0/companies(666e508d-9abb-ea11-bbac-000d3a492c82)/items(a5dc88b9-9abb-ea11-bbac-000d3a492c82)
但是当我尝试使用自定义API进行相同操作时:
myBcServer:Port/bc/api/contoso/app1/v2.0/companies(666e508d-9abb-ea11-bbac-000d3a492c82)/items(a5dc88b9-9abb-ea11-bbac-000d3a492c82)
"error": {
"code": "BadRequest_NotFound","message": "Bad Request - Error in query Syntax. CorrelationId: f7bc0b59-45ac-4293-9f94-108d6436272c."
}
我可以在/items
上成功调用两个API版本。我从那里得到所有物品的清单。
page 50101 ItemsCustomApi
{
PageType = API;
Caption = 'API: Items';
APIPublisher = 'contoso';
APIGroup = 'app1';
APIVersion = 'v2.0';
EntityName = 'item';
EntitySetName = 'items';
SourceTable = Item;
DelayedInsert = true;
Editable = false;
layout
{
area(Content)
{
field(id; SystemId)
{
Caption = 'ID';
}
field("No"; "No.")
{
Caption = 'No.';
}
field("UnitPrice"; "Unit Price")
{
Caption = 'Unit Price';
}
field("vendorNo"; "vendor No.")
{
Caption = 'vendor No.';
}
}
}
}
我怀疑我需要向页面添加一个属性,例如CanGetById = true
。但是,我不知道。
BC版本在docker中运行:mcr.microsoft.com/businesscentral/sandBox:dk Docker版本:V19.03.12
解决方法
您需要设置页面属性ODataKeyFields
才能通过ID进行选择:
ODataKeyFields = SystemId;