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
0
Comments
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.
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.
Substitute INIT with a CLEAR function and should work.
- 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.
Off-Topic: Are you sure about this? After a CLEAR of GL Entry for example, the field "Open" is still yes.
http://msdn.microsoft.com/en-us/library/dd355114.aspx
Method 1:
recRetroDiscProposalHeader.INIT;
CLEAR (recRetroDiscProposalHeader."No.");
Method 2:
CLEAR (recRetroDiscProposalHeader);
Based upon the comments, I have opted for Method 1