No. Series control - Inserting Multiple Records
doddwell
Member Posts: 65
Hello
I have a table called Retro Proposal. The Retro Proposal Insert Trigger uses the NoSeriesManagement Code Unit function InitSeries.
I have a code unit called Retro Management. A function in the Retro Management code unit loops through some records and creates Retro Proposal Records. If there is only one record to create, all is well. If there is more than one record to create I get an error "The Retro Proposal Already Exists".
What's the standard way of getting around this? Is it to call RetroProposal.INSERT(FALSE) and get the Retro Management code unit to get the numbers from NoSeriesManagement rather than getting the insert trigger to get the numbers?
Thanks for any advice, Simon
I have a table called Retro Proposal. The Retro Proposal Insert Trigger uses the NoSeriesManagement Code Unit function InitSeries.
I have a code unit called Retro Management. A function in the Retro Management code unit loops through some records and creates Retro Proposal Records. If there is only one record to create, all is well. If there is more than one record to create I get an error "The Retro Proposal Already Exists".
What's the standard way of getting around this? Is it to call RetroProposal.INSERT(FALSE) and get the Retro Management code unit to get the numbers from NoSeriesManagement rather than getting the insert trigger to get the numbers?
Thanks for any advice, Simon
0
Comments
-
Empty the field which the numberseries fills before inserting, it is probably still filled with the number from the previous record ( INIT does not initialize primary key fields )0
-
Hello
I'm not sure what you mean - how do I "empty" the field? This is the Code Unit Snippet (it's part of a repeat loop so lots of records could get created):
IF recSalesInvoiceHeader.FINDFIRST THEN BEGIN
recRetroDiscProposalHeader.INIT;
recRetroDiscProposalHeader."Sell-to Customer No." := CustomerNumber;
recRetroDiscProposalHeader."Retro. Disc. Header No." := recRetroDiscSchedule."Retro. Disc. Header No.";
recRetroDiscProposalHeader."Start Date" := recRetroDiscSchedule."Start Date";
recRetroDiscProposalHeader."End Date" := recRetroDiscSchedule."End Date";
recRetroDiscProposalHeader."Posting Type" := recRetroDiscSchedule.Type;
recRetroDiscProposalHeader."Retro Disc. Schedule No." := recRetroDiscSchedule."No.";
recRetroDiscProposalHeader.INSERT(TRUE);
END;
This is the code in the Insert Trigger on the Proposal Table:
IF "No." = '' THEN BEGIN
RetroDiscSetup.GET;
RetroDiscSetup.TESTFIELD(RetroDiscSetup."Retro Discount Nos.");
NoSeriesMgt.InitSeries(RetroDiscSetup."Retro Discount Nos.",xRec."No. Series",0D,"No.","No. Series");
END;
Thanks very much.0 -
After the...
recRetroDiscProposalHeader.INIT;
...you need to add...
recRetroDiscProposalHeader."No." := '';
...to clear the value so that it is set again to the next number in OnInsert trigger.0 -
As MBergerm said, INIT function doesn't initialize primary key fields, so when you create the second record and recRetroDiscProposalHeader.INSERT(TRUE) is called, "No." field is still filled with the no. of the first record and code inside the IF statement isn't executed.
Substitute INIT with a CLEAR function and should work.* Daniele Rebussi * | * Rebu NAV Diary *0 -
As Geordie said, CLEAR will also work (instead of INIT) but note that this also has other side effects, e.g.
- filters will be cleared
- current key will be reset
- most importantly in your case, and fields with an InitValue property specified will NOT be set to the InitValue value but instead will be set to the default value (e.g. 0 for integer/decimal, false for Boolean etc...)
...for these reasons it's better to leave the INIT there and then explicitly clear the "No." Field value instead of using the CLEAR statement.0 -
Kishorm wrote:As Geordie said, CLEAR will also work (instead of INIT) but note that this also has other side effects, e.g.
- most importantly in your case, and fields with an InitValue property specified will NOT be set to the InitValue value but instead will be set to the default value (e.g. 0 for integer/decimal, false for Boolean etc...)
...for these reasons it's better to leave the INIT there and then explicitly clear the "No." Field value instead of using the CLEAR statement.
Off-Topic: Are you sure about this? After a CLEAR of GL Entry for example, the field "Open" is still yes.0 -
EDIT: Oops, I was wrong, The Microsoft documentation says it does initialise the record...
http://msdn.microsoft.com/en-us/library/dd355114.aspx0 -
Thanks for all of your replies. I tried both methods and both worked:
Method 1:
recRetroDiscProposalHeader.INIT;
CLEAR (recRetroDiscProposalHeader."No.");
Method 2:
CLEAR (recRetroDiscProposalHeader);
Based upon the comments, I have opted for Method 10
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 322 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
