Unique record to export
zac
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
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
0
Answers
-
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.0 -
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.Ron0 -
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.0 -
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.Ron0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 250 Dynamics CRM
- 102 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions