Dataport import problem

tompynationtompynation Member Posts: 398
Hi, i created a dataport which reads a csv file, and insert the records in to the Purchase Price table.

The following records are in my csv file and should be imported:

Enabled SourceExpr StartPos Width
Yes "Vendor No." 0 0
Yes "Item No." 0 0
Yes "Vendor Item No." 0 0
Yes "Unit of Measure Code" 0 0
Yes "Currency Code" 0 0
Yes "Direct Unit Cost" 0 0
Yes "Starting Date" 0 0
Yes "Ending Date" 0 0

Now, the problem is that "Vendor Item No." is not a field inside the Purchase Price Table, so i added this field as a C/AL Global...

Now when the csv file dont contains an "Item No." then the "Vendor Item No." will be filled in... with this "Vendor Item No." i should select the corresponding "Item No." form the table "Item Cross-Reference"

So i wrote this code which should perform the lookup of the corresponding "Item No.":

OnBeforeImportRecord:

IF "Item No." = '' THEN BEGIN
itemCrossRefRec.SETRANGE("Cross-Reference Type No.", "Vendor No.");
itemCrossRefRec.SETRANGE("Cross-Reference No.", "Vendor Item No.");
IF itemCrossRefRec.FIND THEN BEGIN
"Item No." := itemCrossRefRec."Item No.";
MESSAGE('Opgehaald Item No.: ' + FORMAT("Item No."));
END;
END;

The problem now is that the values of the Fields "Vendor No." and "Vendor Item No." are zero in side this method :?:

How can i get the values from my csv corresponding to the empy "Item No." ?

Answers

  • bbrownbbrown Member Posts: 3,268
    Move your code to the OnAfterImportTrigger. The record is read in this trigger and not OnBeforeImportTrigger.

    Also in OnBeforeImportRecord add:

    CLEAR('Your Record VAR')
    There are no bugs - only undocumented features.
  • tompynationtompynation Member Posts: 398
    if i move my code, to the on AfterImportRec

    I get an error warning me 'The field cannot be empty, please enter a value'

    The field they are talkin about is the 'Item No.'
    Which should be filled up with the code that i moved...
  • tompynationtompynation Member Posts: 398
    Solved the problem :lol:

    OnAfterImportRecord:


    IF gv_ItemNo = '' THEN BEGIN
    itemCrossRefRec.SETRANGE("Cross-Reference Type No.", "Purchase Price"."Vendor No.");
    itemCrossRefRec.SETRANGE("Cross-Reference No.", gv_ItemVendorNo);
    IF itemCrossRefRec.FIND('-') THEN BEGIN
    "Purchase Price"."Item No." := itemCrossRefRec."Item No.";
    END;
    END
    ELSE BEGIN
    "Purchase Price"."Item No." := gv_ItemNo;
    END;

    IF NOT "Purchase Price".INSERT THEN
    "Purchase Price".MODIFY;


    And i made the "Item No." as a C/AL global to instead of a dataport field
Sign In or Register to comment.