BJECT Dataport 50048 GL Budget Load { OBJECT-PROPERTIES { Date=13/05/09; Time=13:23:10; Modified=Yes; Version List=HB-MWA; } PROPERTIES { OnInitDataport=BEGIN // "Delete Pre Existing Budget" := FALSE; END; } DATAITEMS { { PROPERTIES { DataItemTable=Table96; OnAfterImportRecord=BEGIN // Create a Budget Name record if it does not already exist IF NOT newglbudname.GET("Budget Name") THEN BEGIN newglbudname.INIT; newglbudname.Name := "Budget Name"; newglbudname.Description := Budget_Desc; newglbudname.INSERT(TRUE) END; // Get next Budget Lines Entry No. IF newglbudent.FIND('+') THEN EntryNo := newglbudent."Entry No." + 1 ELSE EntryNo := 1; // Create Budget Line Entries IF NOT "G/L Budget Entry".GET(EntryNo) THEN BEGIN newglbudent.INIT; newglbudent."Entry No." := EntryNo; newglbudent.VALIDATE("Budget Name","Budget Name"); newglbudent.VALIDATE("G/L Account No.", "G/L Account No."); newglbudent.Date := Date; newglbudent.VALIDATE("Global Dimension 1 Code", "Global Dimension 1 Code"); newglbudent.VALIDATE("Global Dimension 2 Code","Global Dimension 2 Code"); newglbudent.Amount := Amount; newglbudent."User ID" := USERID; IF Description = '' THEN newglbudent.Description := 'Imported on ' + FORMAT(WORKDATE,0,'<Day> <Month Text> <Year>') ELSE newglbudent.Description := Description; newglbudent.INSERT(TRUE); END ELSE ERROR('Duplicate Entry No.'); END; } FIELDS { { ; ;"Budget Name" } { ; ;Budget_Desc } { ; ;"G/L Account No." } { ; ;Date } { ; ;Amount } { ; ;Description } { ; ;"Global Dimension 1 Code" } { ; ;"Global Dimension 2 Code" } } } } REQUESTFORM { PROPERTIES { Width=9020; Height=3410; } CONTROLS { } } CODE { VAR Budget_Desc@1000000000 : Text[80]; newglbudname@1000000001 : Record 95; newglbudent@1000000002 : Record 96; "Delete Pre Existing Budget"@1000000003 : Boolean; EntryNo@1000000004 : Integer; BEGIN END. } }
Comments
Without testing it, my first reaction is that there are blank lines at the bottom of the file.
Dynamics Nav Add-ons
http://www.simplydynamics.ie/Addons.html
// Create Budget Line Entries
IF NOT "G/L Budget Entry".GET(EntryNo) THEN BEGIN
It's going to confuse the dataport.
I would suggest you assign the record to a local record, insert this and prevent the dataport from adding records.
// Create Budget Line Entries
IF NOT newglbudent.GET(EntryNo) THEN BEGIN
and it made no difference. Is this what you meant?
I suspect what is happening is:
First record - the dataport is creating a record ( entry 0 as this is not assigned) and the then code is creating another
Second record - the dataport overwrites record 0 and then the code is creating another
...
...
Last record - the dataport overwrites record 0 and then the code is creating another
so you end up with the last record duplicated.
Solution:
1. Add code to set the entry no. and remove the code to create the records
2. let the code create the records and turn off Autosave property
Dynamics Nav Add-ons
http://www.simplydynamics.ie/Addons.html
My Blog - nav.education
Microsoft Certified Business Management Solutions Professional
Microsoft Certified Business Management Solutions Specialist
http://www.navisiontech.com
turning off the autosave/autoinsert worked a treat.