Transfering global variable during dataimport

tompynationtompynation Member Posts: 398
Hi, i've created a dataimport which insert records to specefied table...

Now i would like to check when i insert a record, that its a valid value.
So i wrote this code which check this:

OnAfterImportRecord():

IF NOT LocRec.GET("Location Code")
THEN BEGIN
IF SYSTEM.STRLEN(FoutMelding) >= 200
THEN BEGIN
ERROR(FoutAlgemeen);
END;

IF SYSTEM.STRPOS(FoutMelding,"Location Code") = 0
THEN BEGIN
FoutMelding += FORMAT("Location Code" + ',');
END;
END;

This check works fine, now i would like to notify the user if the file which is being imported contains invalid values.
So i added this code

OnPostDataItem():

IF FoutMelding <> ''
THEN MESSAGE(TextFout + ' ' + FoutMelding);

COMMIT;

The problem now is that my FoutMelding (G/AL Global variable) is empty
inside the OnPostDataItem() method... but i'm sure it isnt empty inside the OnAfterImportRecord() method.

Is it possible that navasion forgets the value from my FoutMelding when it executes the OnPostDataItem() ?

Answers

  • SavatageSavatage Member Posts: 7,142
    Do you want to let them know if there was simply an invalid entry(s) or not (Yes/No)
    -or-
    Do you want the dataport to save all the invalid entries in some temptable to be displayed later?
  • tompynationtompynation Member Posts: 398
    i want to warn the user that there were invalid values in the file that was imported, and i want to show these invalid values...
    So i store these values in FoutMelding.

    The import should also not be executed when there are invalid values in side the file which is being imported.
  • SavatageSavatage Member Posts: 7,142
    ON post dataitem is only gonna fire at the end.
    I don't think this is what you need.

    If you use your Message on the onafterimportrecord the user will see it.

    you can also use CurrDataport.SKIP to bypass these invalid entries.
    If you use ERROR('Blah Blah') instead of MESSAGE it will stop.
    or you could also add a CONFIRM so the user can decide whether to continue on or stop.

    Unless I'm not understanding :-k
  • tompynationtompynation Member Posts: 398
    Yes i know that the onPostDataItem is only fired 1 ( at the end)
    Thats what i need, cause when my file (which is going to be imported)
    contains more then 100 invalid entries... i dont want the user to click 100 times to confirm the error message...

    So i would show the error only at the end, show him which values are invalid, so he can adjust his file, and then restart the import.

    But the only problem here is that inside the OnPostDataItem my
    global variable FoutMelding suddently becomes empty, while it is filled with the invalid values inside the OnAfterImportRecord()...
  • SavatageSavatage Member Posts: 7,142
    Savatage wrote:

    This link discusses - sending the invalid data to a temptable and printing a report of all the errors at the end of the dataport.

    addtional info here: http://www.mibuso.com/howtoinfo.asp?FileID=6
  • DenSterDenSter Member Posts: 8,305
    What did you say Harry? :mrgreen:
  • tompynationtompynation Member Posts: 398
    solved :lol:

    On the Dataport Designer:

    Click on the first blanco line under the dataitem

    And added the code which handles the "FoutMelding":

    OnPostDataPort:

    IF (FoutMelding <> '') OR (FoutMeldingZone <> '')
    THEN BEGIN
    ERROR(TextFout + '\' + FoutMelding + '\' + TextFoutZone + '\' + FoutMeldingZone + '\' + FoutAlgemeen);
    END;
Sign In or Register to comment.