Skip to main content

Notifications

Business Central forum
Answered

Sales Invoice Line - Populate shortcut dimensions from API call

Posted on by 2,254

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?

Categories:
  • Suggested answer
    Vaishnavi J Profile Picture
    Vaishnavi J 3,056 on at
    RE: Sales Invoice Line - Populate shortcut dimensions from API call

    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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,469 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans