Dataport Problem

jayordanjayordan Member Posts: 7
I'm trying to import via a Dataport and am having problems importing a field into the Shortcut Dimension 1 Field.

I have a fixed txt file as the import; and am importing to the Gen. Journal Line table.

Here is the code I have so far...
Gen. Journal Line - OnBeforeImportRecord()
// GenJnlLine-Temporary table created, variable created in view, C/AL GLOBALS
// Filters the GenJnlLine (temp table) to General and P-Card
// If it finds something on the last line of the GenJnlLine, then it assigns the variable
//    LineNo to that last line, otherwise it assigns the variable LineNo to '0'.
                                                    
GenJnlLine.SETRANGE("Journal Template Name",'GENERAL');
GenJnlLine.SETRANGE("Journal Batch Name",'P-CARD');
IF GenJnlLine.FIND('+') THEN
   LineNo := GenJnlLine."Line No."
ELSE
   LineNo := 0;


Gen. Journal Line - OnAfterImportRecord()

// Set field values that are not in the export file (set primary keys or required fields)

"Journal Template Name" := 'GENERAL';
"Journal Batch Name" := 'P-CARD';
"Line No." := LineNo + 10000;
"Account Type" := "Account Type"::"G/L Account";
"Document Type" := "Document Type"::Payment;
"Document No." := 'PCARD';

// Perform validations to fill in other system fields.

Amount_V := Amount / 100;
VALIDATE(Amount, Amount_V);
VALIDATE("Account No.");


// Add the Balancing Account information
VALIDATE("Bal. Account Type","Bal. Account Type"::"G/L Account");
VALIDATE("Bal. Account No.",'2023');

Any suggestions?

Comments

  • kinekine Member Posts: 12,562
    The steps for simulating manual entering is still same:

    1. fill Primary key fields
    2. INSERT(True)
    3. fill other fields
    4. MODIFY(True)

    In this way the Dimensions can be correctly inserted because in time of filling the fields the record exists and the entry into Dimension table can be entered...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • KarenhKarenh Member Posts: 209
    Are you importing the dimension code directly to the field (I don't see it in the code, so I assume so).

    When you validate the account no., the dimension value would be overwritten. I suggest importing to a variable for the dimension, then assigning the value to the field AFTER validating the account no. I would do the assignment via a validation so the corresponding dimension table is also updated.

    Also, if the GenJnlLine is a temporary table, then you cannot get the last line no. from it. I suggest that it not be a temporary table; that you move that block of code to the OnAfterImportRecord trigger, and that you LOCKTABLE so you don't have a problem if other uses are adding records.
  • jayordanjayordan Member Posts: 7
    I am importing from a txt file, into the field "Shortcut Dimension 1 Code" using VALIDATE("Shortcut Dimension 1 Code"); after the VALIDATE("Account No."); line.
  • KarenhKarenh Member Posts: 209
    I suggest that you import to a variable instead of the Shortcut Dimension 1 field.

    Then VALIDATE("Shortcut Dimension 1 Code", vDim1);
  • jayordanjayordan Member Posts: 7
    Ok,

    So I changed the code in the OnAfterImportRecord(), created a global variable Dept_Code_V, but no go on the import. I'm confused as to why it isn't working.

    KarenH any helP?

    :
    // Set field values that are not in the export file (set primary keys or required fields)
    
    "Journal Template Name" := 'GENERAL';
    "Journal Batch Name" := 'P-CARD';
    "Line No." := LineNo + 10000;
    "Account Type" := "Account Type"::"G/L Account";
    "Document Type" := "Document Type"::Payment;
    "Document No." := 'PCARD';
    
    // Perform validations to fill in other system fields.
    Dept_Code_V := "Shortcut Dimension 1 Code";
    VALIDATE("Shortcut Dimension 1 Code", Dept_Code_V);
    Amount_V := Amount / 100;
    VALIDATE(Amount, Amount_V);
    
    
    
    // Add the Balancing Account information
    VALIDATE("Bal. Account Type","Bal. Account Type"::"G/L Account");
    VALIDATE("Bal. Account No.",'2023');
    
  • jayordanjayordan Member Posts: 7
    Ok :mrgreen:
    So I figured it out...

    Looks like the answer was when I was validating the Bal. Account No, the dimension value was overwritte.

    Thanks KAREN!!
Sign In or Register to comment.