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 :
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,247

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)
  • Suggested answer
    Andy Sather Profile Picture
    on at

    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.

  • Verified answer
    Samantha73 Profile Picture
    3,247 on at

    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 :)

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans