Skip to content
Open

Update #5025

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// ------------------------------------------------------------------------------------------------
namespace Microsoft.eServices.EDocument.Helpers;

using System.Utilities;

codeunit 6121 "EDocument Json Helper"
{
Access = Internal;
Expand Down Expand Up @@ -41,6 +43,16 @@ codeunit 6121 "EDocument Json Helper"
exit(JsonToken.AsObject());
end;

internal procedure GetKeyValuePairsArray(SourceJsonObject: JsonObject): JsonArray
var
JsonToken: JsonToken;
ContentObject: JsonObject;
begin
ContentObject := GetInnerObject(SourceJsonObject);
ContentObject.Get('key_value_pairs', JsonToken);
exit(JsonToken.AsArray());
end;

internal procedure SetStringValueInField(FieldName: Text; MaxStrLen: Integer; var FieldsJsonObject: JsonObject; var Field: Text)
var
JsonValue: JsonValue;
Expand Down Expand Up @@ -109,6 +121,47 @@ codeunit 6121 "EDocument Json Helper"
exit(true);
end;

internal procedure GetKeyValuePairsArray(StructuredData: Codeunit "Temp Blob"): JsonObject
var
InStream: InStream;
SourceJsonObject: JsonObject;
KeyValuePairsArray: JsonArray;
BlobAsText: Text;
begin
StructuredData.CreateInStream(InStream, TextEncoding::UTF8);
InStream.Read(BlobAsText);
SourceJsonObject.ReadFrom(BlobAsText);

KeyValuePairsArray := GetKeyValuePairsArray(SourceJsonObject);
exit(ExtractKeysAndValuesFromKeyValuePairsArray(KeyValuePairsArray));
end;

internal procedure ExtractKeysAndValuesFromKeyValuePairsArray(var KeyValuePairsArray: JsonArray): JsonObject
var
KVObject, NewKV, ResultKVPairs : JsonObject;
KVToken: JsonToken;
KeyText, Value : Text;
ADIConfidence: Decimal;
begin
foreach KVToken in KeyValuePairsArray do begin
if not KVToken.IsObject() then
continue;
KVObject := KVToken.AsObject();
KeyText := KVObject.GetText('key', false);
Value := KVObject.GetText('value', false);
ADIConfidence := KVObject.GetDecimal('confidence', true);
if ResultKVPairs.Contains(KeyText) then
continue;
if ADIConfidence > 0.1 then begin
Clear(NewKV);
NewKV.Add('value', Value);
NewKV.Add('confidence', ADIConfidence);
ResultKVPairs.Add(KeyText, NewKV);
end;
end;
exit(ResultKVPairs);
end;

[TryFunction]
internal procedure TryAssignToText(JsonValue: JsonValue; MaxStrLen: Integer; var TextValue: Text)
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Microsoft.eServices.EDocument.Processing.Import;

using Microsoft.eServices.EDocument.Processing.Import.Purchase;
using Microsoft.eServices.EDocument;
using Microsoft.eServices.EDocument.Helpers;

page 6182 "E-Doc. Readable Purchase Doc."
{
Expand Down Expand Up @@ -224,6 +226,16 @@ page 6182 "E-Doc. Readable Purchase Doc."
Caption = 'Total';
ToolTip = 'Specifies the total.';
}
field(KeyValuePairs; KeyValuePairs)
{
Caption = 'Key Value Pairs';
ToolTip = 'Specifies the key value pairs found in the document that could not be mapped to other fields.';
Importance = Additional;
MultiLine = true;
Editable = false;
ApplicationArea = All;
Visible = true;
}
}
part("Lines"; "E-Doc. Read. Purch. Lines")
{
Expand All @@ -236,6 +248,7 @@ page 6182 "E-Doc. Readable Purchase Doc."
trigger OnAfterGetRecord()
begin
DataCaption := 'Extracted Data - Purchase Document ' + Format(Rec."E-Document Entry No.");
ExtractKeyValuePairs();
end;

trigger OnOpenPage()
Expand All @@ -252,6 +265,17 @@ page 6182 "E-Doc. Readable Purchase Doc."
CurrPage.Lines.Page.SetBuffer(EDocumentPurchaseLine);
end;

local procedure ExtractKeyValuePairs(): Text
var
EDocument: Record "E-Document";
EDocumentDataStorage: Record "E-Doc. Data Storage";
EDocumentJsonHelper: Codeunit "EDocument Json Helper";
begin
EDocument.Get(Rec."E-Document Entry No.");
if EDocumentDataStorage.Get(EDocument."Structured Data Entry No.") then
EDocumentJsonHelper.GetKeyValuePairsArray(EDocumentDataStorage.GetTempBlob()).WriteTo(KeyValuePairs);
end;

var
DataCaption: Text;
DataCaption, KeyValuePairs : Text;
}
Loading