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

Notifications

Announcements

Community site session details

Community site session details

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

Get Shipment No. issue in trigger OnInsert

(0) ShareShare
ReportReport
Posted on by 140

Hi Experts,


We create a custom table and service for this table in our extension.

this table is used to record the the posted sales shipment No. and Posted sales Inovice No. after we post the sales order.

Now one of our customer always encounter problem like below,

{"error":{"code":"Internal_EntityWithSameKeyExists","message":"The record in table TRCCreateShipmentsNew already exists. Identification fields and values: SoNum='S-SHPT103999' CorrelationId: 9838540c-8c47-4265-9c7b-e2ea0a73b7cf."}}

pastedimage1602496661791v1.png

but actually this shipment No. is no existed in the 365BC company. I also find this shipment is the Ending No. we set for posted Sales Shipment in the "No. Series"
Below is a screenshot for the trigger OnInsert  for the table,  after we call code unit for the post shipment, we will get the last record in the "Sales Shipment Header".

I am not able to reproduce this issue in my local environment, I am confused for it.Can anyone shed me some lights on this issue?

pastedimage1602496661792v2.png

Thanks

I have the same question (0)
  • RahulBansode Profile Picture
    171 on at

    Could you add some screenshots of better quality? Neither the code nor the table are visible.

  • Denny1986 Profile Picture
    140 on at

    Below is our code for the trigger

    trigger OnInsert()

       var

           salesOrder: Record "Sales Header";

           shipment: Record "Sales Shipment Header";

           recpostedInvoice: Record "Sales Invoice Header";

           cusalesPost: Codeunit "Sales-Post";

           orderNum: Code[30];

           recPostedInvoiceLine: Record "Sales Invoice Line";

       begin

           orderNum := rec.SoNum;

           salesOrder.Reset();

           if salesOrder.Get(salesOrder."Document Type"::Order, Rec.SoNum) then

               if rec.createInvoice then begin

                   salesOrder.Ship := true;

                   salesOrder.Invoice := true;

                   cusalesPost.Run(salesOrder);

                   shipment.Init();

                   if shipment.FindLast() then begin

                       Rec."No." := shipment."No.";

                       Rec."Sell-to Customer No." := shipment."Sell-to Customer No.";

                       Rec."Bill-to Customer No." := shipment."Bill-to Customer No.";

                       Rec."Order Date" := shipment."Order Date";

                       Rec."Shipment Date" := shipment."Shipment Date";

                   end;

                   SoNum := shipment."No.";

              end;

    end;

  • Suggested answer
    Mohana Yadav Profile Picture
    61,019 Super User 2025 Season 2 on at

    what is the last record in Sales Shipment Header?

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

News and Announcements

Season of Giving Solutions is Here!

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 1,638

#2
YUN ZHU Profile Picture

YUN ZHU 837 Super User 2025 Season 2

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 704 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans