Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

Cannot Insert Second Record into Temp Table

Posted on by 234

Dear All,

 

I created a temp table and then want to insert records from another table. but cannot insert, pop up message: "The Sales Line already exists. Identification fields and values: Document Type ='Quote'......"

 

my codeing is written onAfterGetRecord -

"Sales Line".SETFILTER("Document Type",'Order');

IF "Sales Line".FINDSET THEN  

REPEAT    

TempSalesLine.INIT;     

TempSalesLine."Document No." := "Document No.";   

TempSalesLine."No." := "No.";      

TempSalesLine.INSERT;     

UNTIL "Sales Line".NEXT = 0;

 

Please help how to solve it, thanks

*This post is locked for comments

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,135 Super User 2024 Season 2 on at
    RE: Cannot Insert Second Record into Temp Table

    You can create a global varialbe for Sales Header and find the record using GET function like

    SalesHeader.Get("Sales Line"."Document Type","Sales Line"."Document No.");

    You need a Date field in Sales Line table to insert Document Date fied of Sales Header as your temp table is based on Sales Line table.

    ex: Shipment Date

    then code sample will be

    TempSalesLine."Shipment Date" := SalesHeader."Document Date";

  • kcchan Profile Picture
    kcchan 234 on at
    RE: Cannot Insert Second Record into Temp Table

    Thanks Mohana,

    Can I ask one more question?

    How can I join the table and insert record into TempSalesLine table?

    e.g.

    there are two tables Sales Header and Sales Line,

    I want to join these two table with SalesHeader.Document Date, SalesLine.Document No.,SalesLine.Amount...etc

    and then insert those field into TempSalesLine table.

    Can you give me some hints and example?

    Thank you very much

  • kcchan Profile Picture
    kcchan 234 on at
    RE: Cannot Insert Second Record into Temp Table

    Thanks a lot

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,135 Super User 2024 Season 2 on at
    RE: Cannot Insert Second Record into Temp Table

    In which Tables - onAfterGetRecord trigger did you write above code?

    Is it Sales Line?

    Then you need to move

    "Sales Line".SETFILTER("Document Type",'Order');

    to OnPreDatItem trigger

    and remove FindSet and Repeat code..

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,135 Super User 2024 Season 2 on at
    RE: Cannot Insert Second Record into Temp Table

    The Primary key of Sales Line Doc Type, Doc No. and Line No.

    So you have to insert those primary key records must.

    Add below code and try..

    TempSalesLine."Document Type" := "Document Type";  

    TempSalesLine."Line No." := "Line No.";  

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans