Hi All,
Good Morning.
I am using On-Prem Business Central.
I have created on query and then i used the query in my page API to fetch data. But i am facing the blow error.
Good Morning.
I am using On-Prem Business Central.
I have created on query and then i used the query in my page API to fetch data. But i am facing the blow error.
Query Code :
query 50112 GetAllItemsDetails
{
QueryType = API;
APIPublisher = 'a';
APIGroup = 'b';
EntityName = 'Item';
EntitySetName = 'Items';
{
QueryType = API;
APIPublisher = 'a';
APIGroup = 'b';
EntityName = 'Item';
EntitySetName = 'Items';
elements
{
dataitem(ItemDetails; Item)
{
column(ItemNo; "No.")
{
{
dataitem(ItemDetails; Item)
{
column(ItemNo; "No.")
{
}
column(Description; Description)
{
column(Description; Description)
{
}
}
}
}
var
jsonText: Text;
jsonText: Text;
}
Page API code :
page 50101 "Get Item Detail Test"
{
DelayedInsert = true;
PageType = API;
APIVersion = 'v1.0';
APIPublisher = 'q';
APIGroup = 'q1';
EntityName = 'PriceListLine';
EntitySetName = 'PriceListLines';
ODataKeyFields = SystemId;
SourceTable = "Item";
SourceTableTemporary = true;
{
DelayedInsert = true;
PageType = API;
APIVersion = 'v1.0';
APIPublisher = 'q';
APIGroup = 'q1';
EntityName = 'PriceListLine';
EntitySetName = 'PriceListLines';
ODataKeyFields = SystemId;
SourceTable = "Item";
SourceTableTemporary = true;
layout
{
area(content)
{
repeater(Group)
{
field(Id; Rec.SystemId)
{
Caption = 'Id';
}
field("No"; Rec."No.")
{
Caption = 'ItemNo';
}
field(Description; Rec.Description)
{
Caption = 'Description';
}
{
area(content)
{
repeater(Group)
{
field(Id; Rec.SystemId)
{
Caption = 'Id';
}
field("No"; Rec."No.")
{
Caption = 'ItemNo';
}
field(Description; Rec.Description)
{
Caption = 'Description';
}
}
}
}
trigger OnOpenPage()
var
ItemQuery: Query "GetAllItemsDetails";
TempItem: Record Item temporary;
begin
// Run the query and store results in the temporary table
ItemQuery.Open();
while ItemQuery.Read() do begin
TempItem."No." := ItemQuery.ItemNo;
TempItem.Description := ItemQuery.Description;
TempItem.Insert();
end;
ItemQuery.Close();
var
ItemQuery: Query "GetAllItemsDetails";
TempItem: Record Item temporary;
begin
// Run the query and store results in the temporary table
ItemQuery.Open();
while ItemQuery.Read() do begin
TempItem."No." := ItemQuery.ItemNo;
TempItem.Description := ItemQuery.Description;
TempItem.Insert();
end;
ItemQuery.Close();
// Loop through the temporary records and insert into Rec
if TempItem.FindSet() then
repeat
Rec.TransferFields(TempItem); // Copy the fields from TempItem to Rec
if TempItem.FindSet() then
repeat
Rec.TransferFields(TempItem); // Copy the fields from TempItem to Rec
// Rec.:= TempItem; // This one also used.
Rec.Insert(false); // Insert the record into the page dataset
until TempItem.Next() = 0;
Rec.Insert(false); // Insert the record into the page dataset
until TempItem.Next() = 0;
end;
var
TotalRows: Integer;
TotalRows: Integer;
}
Error :
Does anyone have any idea why this is not working in my On-Prem BC. and If anyone have code snip please share.
Thanks for your Help.
Error :
{
"error": {
"code": "Internal_EntityWithSameKeyExists",
"message": "The record in table Item already exists. Identification fields and values: No.='10010500017' CorrelationId: 8aadcac6-c9c7-40d8-9af0-f16fcab47841."
}
}
Does anyone have any idea why this is not working in my On-Prem BC. and If anyone have code snip please share.
Thanks for your Help.
Categories: