Dataport Generating a Duplicate Record
matpod
Member Posts: 16
I have created a dataport to load our initial GL Budgets. The dataport is designed to generate a Budget Name entry where one doesn't exist, and then generate the Budget line entries.
The dataport successfully imports all the data correctly, but then seems to create a duplicate record at the end of the import. This duplicate record is in the Budget Entry table, and has an Entry No. of 0.
Can anyone help?? (as I am not a NAV developer!!)
I have attached the object code at the bottom. Below are the contents of my CSV file:
BUD0109,Budget 1 for 2009,8430,01/01/2009, 150.00 ,,S0001,200701
BUD0109,Budget 1 for 2009,8430,01/02/2009, 135.00 ,,S0001,200701
BUD0109,Budget 1 for 2009,8430,01/03/2009, 110.00 ,,S0001,200701
BUD0109,Budget 1 for 2009,8430,01/01/2009, 250.00 ,,S0002,200701
BUD0109,Budget 1 for 2009,8430,01/02/2009, 270.00 ,,S0002,200701
BUD0109,Budget 1 for 2009,8430,01/03/2009, 340.00 ,TEST1,S0002,200701
Thanks in advance for any advice / help.
The dataport successfully imports all the data correctly, but then seems to create a duplicate record at the end of the import. This duplicate record is in the Budget Entry table, and has an Entry No. of 0.
Can anyone help?? (as I am not a NAV developer!!)
I have attached the object code at the bottom. Below are the contents of my CSV file:
BUD0109,Budget 1 for 2009,8430,01/01/2009, 150.00 ,,S0001,200701
BUD0109,Budget 1 for 2009,8430,01/02/2009, 135.00 ,,S0001,200701
BUD0109,Budget 1 for 2009,8430,01/03/2009, 110.00 ,,S0001,200701
BUD0109,Budget 1 for 2009,8430,01/01/2009, 250.00 ,,S0002,200701
BUD0109,Budget 1 for 2009,8430,01/02/2009, 270.00 ,,S0002,200701
BUD0109,Budget 1 for 2009,8430,01/03/2009, 340.00 ,TEST1,S0002,200701
Thanks in advance for any advice / help.
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.
}
}
0
Comments
-
Hi,
Without testing it, my first reaction is that there are blank lines at the bottom of the file.0 -
That was my first thought, as sometimes generating a csv from excel you get blanks lines a the bottom of the file. But not in this case, the file is just the 6 lines.0
-
I don't think this is a good idea -
// 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.0 -
I tried it with:
// Create Budget Line Entries
IF NOT newglbudent.GET(EntryNo) THEN BEGIN
and it made no difference. Is this what you meant?0 -
Hi,
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 property0 -
Yeah, anytime you want to manually insert the records in the dataport, turn off the AutoInsert, AutoSave properties. If you don't you'll get two records. One from your code insert, and one from the behind the scenes insert by the dataport.0
-
in certain situations, and it would be irresponsible to say when without testing
IF importedtext = '' THEN CurrDataport.SKIP;
at the end of your code in the OnAfterImport works.Microsoft Certified Technology Specialist
Microsoft Certified Business Management Solutions Professional
Microsoft Certified Business Management Solutions Specialist
http://www.navisiontech.com0 -
Thanks folks,
turning off the autosave/autoinsert worked a treat.
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 333 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

