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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Sales Invoice Line - Populate shortcut dimensions from API call

(0) ShareShare
ReportReport
Posted on by 3,390

Hi All

I can populated global dimensions on sales invoice line from an API call using APIv2 architecture.  However non global dimension codes are using a different logic and I'm unable to directly call them. Has anyone been able to insert sales invoice lines with shortcut dimensions using APIV2?

  • Suggested answer
    Vaishnavi J Profile Picture
    3,096 on at

    HI,

    You can follow the below logic. to insert the shortcut dimension in sales invoice lines.

    // After creating a global variable then add in to API as field.

    field(VJ_Dimension3; VJ_DimensionCode[3])
    {
    ApplicationArea = All;
    Caption = 'Dimension 3 Code';


    }

    // use the below logic to insert the dimension code through API.


    trigger OnInsertRecord(BelowxRec: Boolean): Boolean
    var
    SalesInvoiceAggregator: Codeunit "Sales Invoice Aggregator";
    begi

    SalesInvoiceAggregator.PropagateInsertLine(Rec, TempFieldBuffer);
    UpdateDimensionsOnSalesLine();

    end;

    local procedure UpdateDimensionsOnSalesLine()
    var
    Rec_SalesLine: Record "Sales Line";
    Rec_SalesHeader: Record "Sales Header";
    begin
    Clear(Rec_SalesHeader);
    Rec_SalesHeader.Reset();
    if Rec_SalesHeader.GetBySystemId(Rec."Document Id") then begin
    Clear(Rec_SalesLine);
    Rec_SalesLine.Reset();
    Rec_SalesLine.SetRange("Document Type", Rec_SalesLine."Document Type"::Invoice);
    Rec_SalesLine.SetRange("Document No.", Rec_SalesHeader."No.");
    Rec_SalesLine.SetRange("Line No.", Rec."Line No.");
    if Rec_SalesLine.FindFirst() then begin
    Rec_SalesLine.Validate("Shortcut Dimension 1 Code", VJ_DimensionCode[1]);
    Rec_SalesLine.Validate("Shortcut Dimension 2 Code", VJ_DimensionCode[2]);

    Rec_SalesLine.ValidateShortcutDimCode(3, VJ_DimensionCode[3]);
    Rec_SalesLine.ValidateShortcutDimCode(4, VJ_DimensionCode[4]);
    Rec_SalesLine.ValidateShortcutDimCode(5, VJ_DimensionCode[5]);
    Rec_SalesLine.ValidateShortcutDimCode(6, VJ_DimensionCode[6]);
    Rec_SalesLine.ValidateShortcutDimCode(7, VJ_DimensionCode[7]);
    Rec_SalesLine.ValidateShortcutDimCode(8, VJ_DimensionCode[8]);
    Rec_SalesLine.Modify(false);
    end;
    end
    else
    Error(SalesHeaderNotFoundErr, Rec."Document Id");
    end;


    // create a global variable
    var

    VJ_DimensionCode: Array[8] of Code[20];

    If my answer was helpful to you, please verify it so that other users know it worked. Thank you very much.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 741 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 514 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 336 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans