Dataport Generating a Duplicate Record

matpodmatpod 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.
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

  • DaveTDaveT Member Posts: 1,039
    Hi,

    Without testing it, my first reaction is that there are blank lines at the bottom of the file.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • matpodmatpod Member Posts: 16
    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.
  • SimonWSimonW Member Posts: 77
    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.
  • matpodmatpod Member Posts: 16
    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?
  • DaveTDaveT Member Posts: 1,039
    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 property
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • matttraxmatttrax Member Posts: 2,309
    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.
  • gvolkovgvolkov Member Posts: 196
    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.com
  • matpodmatpod Member Posts: 16
    Thanks folks,

    turning off the autosave/autoinsert worked a treat.
    :)
Sign In or Register to comment.