web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Business Central forum

How Can I Specify Invoice Dimensions via the API?

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    I Gusti Made Ari Profile Picture
    3,600 on at

    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 : 

    https://github.com/Microsoft/AL/issues/4434

  • Community Member Profile Picture
    on at

    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.

  • Suggested answer
    I Gusti Made Ari Profile Picture
    3,600 on at

    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

  • Community Member Profile Picture
    on at

    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.

  • Suggested answer
    dawiehyman Profile Picture
    25 on at

    Yes! Thank you for this code. Exactly what I was looking for, as someone fairly new to AL. I am going to try it.

  • dawiehyman Profile Picture
    25 on at

    How does one associate these with the OnAfterInsert trigger for the Sales Invoice Entity Aggregate table?  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans