{"title":"Codeunit 6163 E-Doc. PO Copilot Matching, extension points 29","url":"https://jonas-paprotka.de/ref/codeunit/6163-e-doc-po-copilot-matching/points/","author":"JOP-AL","license":"Metadata from Microsoft's symbol packages. AL source MIT, Copyright (c) Microsoft Corporation. Selection and wording © 2026 JOP-AL. https://jonas-paprotka.de/licenses/","subject":"Microsoft Dynamics 365 Business Central","checked":"2026-11-20","changed":"2026-10-05","object":{"type":"codeunit","id":6163,"name":"E-Doc. PO Copilot Matching","app":"E-Document Core","url":"https://jonas-paprotka.de/ref/codeunit/6163-e-doc-po-copilot-matching/"},"major":29,"source":{"url":"https://jonas-paprotka.de/ref/codeunit/6163-e-doc-po-copilot-matching/source/","path":"src/Apps/W1/EDocument/App/src/Processing/OrderMatching/Copilot/EDocPOCopilotMatching.Codeunit.al","commit":"4303e5e584d3aa5d9e98cbc615525a5396ad6ed7","lines":"a line is <source url>#L<line>"},"steps":{"event":"[line, \"event\", name, handled]: raises an event of this object; handled 1 when it has an IsHandled parameter","call":"[line, \"call\", name, arguments]: calls a procedure of this object","ext":"[line, \"ext\", type, id, name, arguments]: calls a procedure of another object, through a variable declared with that type","write":"[line, \"write\", table id, method, 1 when called with true]: Insert, Modify, ModifyAll, Delete, DeleteAll or Rename","validate":"[line, \"validate\", table id, field name]","run":"[line, \"run\", type, id]: Codeunit.Run, Page.Run, Report.Run and their kin"},"objects":{"codeunit:8703":{"name":"Feature Telemetry","url":"https://jonas-paprotka.de/ref/codeunit/8703-feature-telemetry/"},"codeunit:7771":{"name":"Azure OpenAI","url":"https://jonas-paprotka.de/ref/codeunit/7771-azure-openai/"},"codeunit:7768":{"name":"AOAI Deployments","url":"https://jonas-paprotka.de/ref/codeunit/7768-aoai-deployments/"},"codeunit:7761":{"name":"AOAI Chat Completion Params","url":"https://jonas-paprotka.de/ref/codeunit/7761-aoai-chat-completion-params/"},"codeunit:6167":{"name":"E-Doc. PO AOAI Function","url":"https://jonas-paprotka.de/ref/codeunit/6167-e-doc-po-aoai-function/"},"codeunit:7763":{"name":"AOAI Chat Messages","url":"https://jonas-paprotka.de/ref/codeunit/7763-aoai-chat-messages/"},"codeunit:7770":{"name":"AOAI Operation Response","url":"https://jonas-paprotka.de/ref/codeunit/7770-aoai-operation-response/"},"codeunit:7758":{"name":"AOAI Function Response","url":"https://jonas-paprotka.de/ref/codeunit/7758-aoai-function-response/"},"codeunit:6109":{"name":"E-Document Import Helper","url":"https://jonas-paprotka.de/ref/codeunit/6109-e-document-import-helper/"},"codeunit:457":{"name":"Environment Information","url":"https://jonas-paprotka.de/ref/codeunit/457-environment-information/"},"codeunit:7773":{"name":"Copilot Capability","url":"https://jonas-paprotka.de/ref/codeunit/7773-copilot-capability/"},"codeunit:6164":{"name":"E-Doc. Line Matching","url":"https://jonas-paprotka.de/ref/codeunit/6164-e-doc-line-matching/"},"table:6163":{"name":"E-Doc. PO Match Prop. Buffer","url":"https://jonas-paprotka.de/ref/table/6163-e-doc-po-match-prop-buffer/"},"table:39":{"name":"Purchase Line","url":"https://jonas-paprotka.de/ref/table/39-purchase-line/"},"codeunit:2200":{"name":"Azure Key Vault","url":"https://jonas-paprotka.de/ref/codeunit/2200-azure-key-vault/"}},"procs":[{"name":"MatchWithCopilot","line":38,"kind":"procedure","params":3,"steps":[[45,"ext","codeunit",8703,"LogUptake",3],[45,"call","FeatureName",0],[50,"call","GetSystemPrompt",0],[54,"call","ApproximateTokenCount",1],[59,"call","BuildUserPrompt",4],[62,"call","ApproximateTokenCount",1],[62,"call","ApproximateTokenCount",1],[63,"call","PromptSizeThreshold",0],[65,"call","PreparePrompt",1],[66,"call","Match",5],[76,"call","PreparePrompt",1],[77,"call","Match",5],[84,"call","GroundCopilotMatching",3]]},{"name":"Match","line":105,"kind":"procedure","params":5,"steps":[[114,"call","FeatureName",0],[117,"ext","codeunit",7771,"SetAuthorization",2],[117,"ext","codeunit",7768,"GetGPT41Latest",0],[118,"ext","codeunit",7771,"SetCopilotCapability",1],[120,"ext","codeunit",7761,"SetMaxTokens",1],[120,"call","MaxTokens",0],[121,"ext","codeunit",7761,"SetTemperature",1],[123,"ext","codeunit",6167,"SetRecords",2],[125,"ext","codeunit",7763,"AddTool",1],[126,"ext","codeunit",7763,"SetFunctionAsToolChoice",1],[126,"ext","codeunit",6167,"GetName",0],[128,"ext","codeunit",7763,"SetPrimarySystemMessage",1],[129,"ext","codeunit",7763,"AddUserMessage",1],[131,"ext","codeunit",7771,"GenerateChatCompletion",3],[132,"ext","codeunit",7770,"IsSuccess",0],[133,"call","FeatureName",0],[135,"ext","codeunit",7770,"IsFunctionCall",0],[136,"ext","codeunit",7770,"GetFunctionResponses",0],[137,"ext","codeunit",7758,"IsSuccess",0],[138,"ext","codeunit",7758,"GetResult",0],[139,"call","FeatureName",0],[141,"ext","codeunit",8703,"LogError",4],[141,"call","FeatureName",0],[141,"ext","codeunit",7758,"GetFunctionName",0],[143,"ext","codeunit",8703,"LogError",4],[143,"call","FeatureName",0],[146,"ext","codeunit",7770,"GetStatusCode",0],[146,"ext","codeunit",7770,"GetError",0],[146,"call","FeatureName",0]]},{"name":"SumUnitCostForAIMatches","line":151,"kind":"procedure","params":1,"steps":[[160,"ext","codeunit",6109,"GetCurrencyRoundingPrecision",1]]},{"name":"RegisterAICapability","line":167,"kind":"procedure","params":0,"steps":[[172,"ext","codeunit",457,"IsSaaSInfrastructure",0],[175,"ext","codeunit",7773,"IsCapabilityRegistered",1],[176,"ext","codeunit",7773,"RegisterCapability",2],[177,"ext","codeunit",8703,"LogUptake",3],[177,"call","FeatureName",0]]},{"name":"GroundCopilotMatching","line":190,"kind":"procedure","access":"local","params":3,"steps":[[201,"ext","codeunit",6164,"MatchOneToOne",3],[205,"write",6163,"Modify"],[207,"write",6163,"Delete"],[209,"write",6163,"Delete"]]},{"name":"BuildUserPrompt","line":214,"kind":"procedure","access":"local","params":4,"steps":[[219,"call","PotentialMatchingPurchaseOrderLine",3],[220,"call","PrepareEDocumentLineStatement",2],[221,"call","PreparePurchaseOrderLineStatement",2]]},{"name":"PotentialMatchingPurchaseOrderLine","line":226,"kind":"procedure","access":"local","params":3,"steps":[[231,"call","IsPOLineWithinCostThreshold",2],[231,"call","DoesLinesHaveQuantityToMatch",2],[233,"write",39,"Insert"]]},{"name":"IsPOLineWithinCostThreshold","line":239,"kind":"procedure","access":"local","params":2,"steps":[[241,"call","CostDifference",4]]},{"name":"GetSystemPrompt","line":279,"kind":"procedure","access":"local","params":0,"steps":[[284,"ext","codeunit",2200,"GetAzureKeyVaultSecret",2],[287,"call","FeatureName",0]]},{"name":"HandleOnRegisterCopilotCapability","line":331,"kind":"procedure","access":"local","params":0,"steps":[[333,"call","RegisterAICapability",0]]}]}