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

Community site session details

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

Dimension set Insert from AL Error when multiple line on invoice

(0) ShareShare
ReportReport
Posted on by 3,150

Hi All

I'm trying to insert sales invoice lines through code.  When inserting dimension set ID it works if the sales invoice has one line but fails when it has more than one line.  Looks like need to clear or reset in the line loop but couldn't find.  Below is the code for sales line insert where dimension set is inserted:

Erro:The record in table Dimension Set Entry already exists. Identification fields and values: Dimension Set ID='0',Dimension Code='Customer Group'

                DimVal.reset;

                

                DimVal.SETFILTER("Dimension Code", '=%1''CUSTOMER GROUP');

                DimVal.SETFILTER(Code'=%1', SalesImportLine.U_ShortcutDimension1Code);

                IF DimVal.FINDFIRST THEN BEGIN

                    Dim1ValID := DimVal."Dimension Value ID";

                    clear(TempDimSetEntry);

                    TempDimSetEntry.RESET;

                    TempDimSetEntry."Dimension Code" := 'CUSTOMER GROUP';

                    TempDimSetEntry."Dimension Value Code" := SalesImportLine.U_ShortcutDimension1Code;

                    TempDimSetEntry."Dimension Value ID" := Dim1ValID; 

                    TempDimSetEntry.INSERT;

                end;

I have the same question (0)
  • Verified answer
    Samantha73 Profile Picture
    3,150 on at
    RE: Dimension set Insert from AL Error when multiple line on invoice

    Morning folks and happy Friday from Australia...If anyone else have this issue ..the solution was to issue a delete statement to the temp table(TempDimSetEntry) before the next iteration of invoice/order line.  In hindsight everything is obvious :)

  • Suggested answer
    Andy Sather Profile Picture
    on at
    RE: Dimension set Insert from AL Error when multiple line on invoice

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sumit Singh Profile Picture

Sumit Singh 3,227

#2
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 2,866

#3
Sohail Ahmed Profile Picture

Sohail Ahmed 2,682 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans