Unique record to export

zaczac Member Posts: 29
Hi folks,
I use dataport to export data in the file. I have records to export and one of the field has a same value in a few records but I would like to export only one record according to that filed. How can I do this? How can I tell dataport to export only one record if value in fileds is the same.
Thanks.
Zac

Answers

  • SogSog Member Posts: 1,023
    unfortunatly there is no distinct function in nav.
    I would hold the printed records in a temporary table. and compare the new record before printing to the temp table.
    If there is a match then skip the record.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • rsaritzkyrsaritzky Member Posts: 469
    You can also write some code in a dataport to do this. In the OnBeforeExportRecord trigger, skip the records that you don't want. Do this by saving the previous record's value so you can compare it to the current record before you export it.

    For example, if you want to export records from G/L Entry, but only one record per G/L Account number, you can do this (Yes, I know this is a bad example, but it will illustrate the technique).
    OnBeforeExportRecord:

    IF "G/L Entry"."G/L Account No." = LastAccountNo THEN
    CurrDataport.SKIP
    ELSE
    LastAccountNo := "G/L Entry"."G/L Account No."

    You can save whatever the comparison criteria you want to avoid duplicates.

    One other thing - you have to "force" a key mismatch on the first record. So put something like this in the
    OnPreDataItem trigger


    The example assumes you want to export the FIRST record that you encounter. You can make the code more sophisticated if that's not what you want.



    LastAccountNo := 'X0X0X0X0X0X0X0X'; // i.e. something that you know will not match any of your keys.
    Ron
  • zaczac Member Posts: 29
    rsaritzky wrote:
    You can also write some code in a dataport to do this. In the OnBeforeExportRecord trigger, skip the records that you don't want. Do this by saving the previous record's value so you can compare it to the current record before you export it.

    For example, if you want to export records from G/L Entry, but only one record per G/L Account number, you can do this (Yes, I know this is a bad example, but it will illustrate the technique).
    OnBeforeExportRecord:

    IF "G/L Entry"."G/L Account No." = LastAccountNo THEN
    CurrDataport.SKIP
    ELSE
    LastAccountNo := "G/L Entry"."G/L Account No."

    You can save whatever the comparison criteria you want to avoid duplicates.

    One other thing - you have to "force" a key mismatch on the first record. So put something like this in the
    OnPreDataItem trigger


    The example assumes you want to export the FIRST record that you encounter. You can make the code more sophisticated if that's not what you want.



    LastAccountNo := 'X0X0X0X0X0X0X0X'; // i.e. something that you know will not match any of your keys.

    Thanks rsaritzky for your observation. I was also thinking to do that but I write in more files it the same time so if I skip dataport iteration then I will lose recordset to handle with it for others files.
  • rsaritzkyrsaritzky Member Posts: 469
    zac wrote:
    Thanks rsaritzky for your observation. I was also thinking to do that but I write in more files it the same time so if I skip dataport iteration then I will lose recordset to handle with it for others files.

    There are always adaptations that have to be made, but even if you're looping through recordsets, you should be able to skip the export at the right time. I'm happy to look at your existing dataport if you want.
    Ron
Sign In or Register to comment.