Hello,
My company's software uses the Dynamics 365 Business Central API to push sales and purchase invoices from our software into BC. That works fine, but we need to be able to specify Dimensions for the invoices during the push. The API does not expose any dimension-related fields for invoices or invoice lines. If a client pushes several hundred invoices each month, we can't reasonably expect them to manually set each invoice's dimensions (let alone all of the individual lines' dimensions) manually: it would take forever.
How can I use the API (or an extension) to allow dimension information to be pushed along with invoices?
Thanks,
Dave
How does one associate these with the OnAfterInsert trigger for the Sales Invoice Entity Aggregate table?
Yes! Thank you for this code. Exactly what I was looking for, as someone fairly new to AL. I am going to try it.
Those fields aren't available on the "Sales Invoice Entity Aggregate" table, unfortunately. I eventually figured this out: in an OnAfterInsert trigger for the Sales Invoice Entity Aggregate table, I want to get the associated "Sales Header" record by document type and number, and associate the dimension set with that record.
codeunit 50141 "Invoice Dimension Association" { var meSalesDocumentTypes: Option Quote,Order,Invoice,"Credit Memo","Blanket Order","Return Order"; mcuDimensionSetTools: Codeunit "Dimension Set Tools"; procedure TieDimensionToSalesInvoiceEntityAggregate(prSalesInvoiceEntityAggregate: Record "Sales Invoice Entity Aggregate") var rSalesHeader: Record "Sales Header"; begin if not rSalesHeader.Get(meSalesDocumentTypes::Invoice, prSalesInvoiceEntityAggregate."No.") then exit; mcuDimensionSetTools.AddDimensionValue( prSalesInvoiceEntityAggregate."Branch Dimension Code", prSalesInvoiceEntityAggregate."Branch Dimension Value Code" ); rSalesHeader."Dimension Set ID" := mcuDimensionSetTools.GetComputedDimensionSetID(); rSalesHeader.Modify(); end; }
And also:
codeunit 50140 "Dimension Set Tools" { var mrTempDimSetEntry: Record "Dimension Set Entry" temporary; mcuDimMgt: Codeunit DimensionManagement; procedure AddDimensionValue(psDimensionCode: Text[20]; psDimensionValueCode: Text[20]) var rDimensionValue: Record "Dimension Value"; begin if not rDimensionValue.Get(psDimensionCode, psDimensionValueCode) then exit; mrTempDimSetEntry.Reset(); mrTempDimSetEntry."Dimension Code" := rDimensionValue."Dimension Code"; mrTempDimSetEntry."Dimension Value Code" := rDimensionValue.Code; mrTempDimSetEntry."Dimension Value ID" := rDimensionValue."Dimension Value ID"; mrTempDimSetEntry.Insert(); end; procedure GetComputedDimensionSetID(): Integer begin exit(mcuDimMgt.GetDimensionSetID(mrTempDimSetEntry)); end; }
Hopefully this helps somebody...took me awhile to figure out how to reliably get a dimension set ID based on a combination of dimension value codes.
if you are using the standard API Page then in this case , please try to add this 2 field with same ID to "Sales Invoice Entity Aggregate" table
- field ID 29 Shortcut Dimension 1 Code
- field ID 30 Shortcut Dimension 2 Code
then pulled out the field to page ID 5475
Hi, thanks for the reply!
I've tried to do that, but can't figure out how. The "Sales Invoice Entity" page exposed via the API is based on a "Sales Invoice Entity Aggregate" record type, which does not have any dimension-related fields on it. I guess, really, I need to know how to navigate to at least the shortcut dimension codes (possibly on the "Sales Invoice Header" object?) FROM the "Sales Invoice Entity" page. I just don't know enough about AL to make that connection, and resources on AL aren't the best right now. Do you know how to go about doing something like that?
Thanks for the tip about API page extensions, too.
Hi , you can try to pulled out the dimension field into the API Page.
Please take note that if you are currently using standard API page , you should not extend it. Instead create a copy from it and modified it to your liking (new Page instead of Page extension). This is because Its prevented in upcoming release and apis will move out of beta in into V1.0
Details :
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,900 Super User 2024 Season 2
Martin Dráb 229,275 Most Valuable Professional
nmaenpaa 101,156