Templates and examples#
นี่คือตัวอย่าง workflow และ template สำหรับ Remove Duplicates node
Continuous examples
ตัวอย่างในส่วนนี้จะเรียงลำดับต่อเนื่องกัน แนะนำให้ทำตามลำดับเพื่อป้องกันผลลัพธ์ที่ไม่คาดคิด
Templates#
Set up sample data using the Code node#
สร้าง workflow พร้อมข้อมูลตัวอย่างเพื่อทดลองใช้ Remove Duplicates node
- เพิ่ม Code node ลงบน canvas แล้วเชื่อมต่อกับ Manual Trigger node
- ใน Code node ให้ตั้งค่า Mode เป็น Run Once for Each Item และ Language เป็น JavaScript
- วางโค้ด JavaScript ด้านล่างนี้ในช่อง JavaScript:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
let data =[]; return { data: [ { id: 1, name: 'Taylor Swift', job: 'Pop star', last_updated: '2024-09-20T10:12:43.493Z' }, { id: 2, name: 'Ed Sheeran', job: 'Singer-songwriter', last_updated: '2024-10-05T08:30:59.493Z' }, { id: 3, name: 'Adele', job: 'Singer-songwriter', last_updated: '2024-10-07T14:15:59.493Z' }, { id: 4, name: 'Bruno Mars', job: 'Singer-songwriter', last_updated: '2024-08-25T17:45:12.493Z' }, { id: 1, name: 'Taylor Swift', job: 'Pop star', last_updated: '2024-09-20T10:12:43.493Z' }, // duplicate { id: 5, name: 'Billie Eilish', job: 'Singer-songwriter', last_updated: '2024-09-10T09:30:12.493Z' }, { id: 6, name: 'Katy Perry', job: 'Pop star', last_updated: '2024-10-08T12:30:45.493Z' }, { id: 2, name: 'Ed Sheeran', job: 'Singer-songwriter', last_updated: '2024-10-05T08:30:59.493Z' }, // duplicate { id: 7, name: 'Lady Gaga', job: 'Pop star', last_updated: '2024-09-15T14:45:30.493Z' }, { id: 8, name: 'Rihanna', job: 'Pop star', last_updated: '2024-10-01T11:50:22.493Z' }, { id: 3, name: 'Adele', job: 'Singer-songwriter', last_updated: '2024-10-07T14:15:59.493Z' }, // duplicate //{ id: 9, name: 'Tom Hanks', job: 'Actor', last_updated: '2024-10-17T13:58:31.493Z' }, //{ id: 0, name: 'Madonna', job: 'Pop star', last_updated: '2024-10-17T17:11:38.493Z' }, //{ id: 15, name: 'Bob Dylan', job: 'Folk singer', last_updated: '2024-09-24T08:03:16.493Z'}, //{ id: 10, name: 'Harry Nilsson', job: 'Singer-songwriter', last_updated: '2020-10-17T17:11:38.493Z' }, //{ id: 11, name: 'Kylie Minogue', job: 'Pop star', last_updated: '2024-10-24T08:03:16.493Z'}, ] }
- เพิ่ม Split Out node ลงบน canvas แล้วเชื่อมต่อกับ Code node
- ใน Split Out node ให้กรอก
data
ในช่อง Fields To Split Out
Removing duplicates from the current input#
- เพิ่ม Remove Duplicates node ลงบน canvas แล้วเชื่อมต่อกับ Split Out node เลือก Remove items repeated within current input ใน Action เพื่อเริ่มต้น
- เปิด Remove Duplicates node แล้วตรวจสอบว่า Operation ตั้งเป็น Remove Items Repeated Within Current Input
- เลือก All fields ในช่อง Compare
- กด Test step เพื่อรัน Remove Duplicates node ข้อมูลที่ซ้ำกันใน input จะถูกลบออก
n8n จะลบรายการที่มีข้อมูลเหมือนกันทุก field ผลลัพธ์ใน table view จะเป็นแบบนี้:
id | name | job | last_updated |
---|---|---|---|
1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
4 | Bruno Mars | Singer-songwriter | 2024-08-25T17:45:12.493Z |
5 | Billie Eilish | Singer-songwriter | 2024-09-10T09:30:12.493Z |
6 | Katy Perry | Pop star | 2024-10-08T12:30:45.493Z |
7 | Lady Gaga | Pop star | 2024-09-15T14:45:30.493Z |
8 | Rihanna | Pop star | 2024-10-01T11:50:22.493Z |
- เปิด Remove Duplicates node อีกครั้งแล้วเปลี่ยน Compare เป็น Selected Fields
- ในช่อง Fields To Compare ให้กรอก
job
- กด Test step เพื่อรัน Remove Duplicates node ข้อมูลที่ซ้ำกันใน field
job
จะถูกลบออก
n8n จะลบรายการที่มีค่า job
ซ้ำกันใน input ผลลัพธ์ใน table view จะเป็นแบบนี้:
id | name | job | last_updated |
---|---|---|---|
1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
Keep items where the value is new#
- เปิด Remove Duplicates node แล้วตั้งค่า Operation เป็น Remove Items Processed in Previous Executions
- ตั้งค่า Keep Items Where เป็น Value Is New
- ตั้งค่า Value to Dedupe On เป็น
{{ $json.name }}
- บน canvas ให้เลือก Test workflow เพื่อรัน workflow แล้วเปิด Remove Duplicates node เพื่อดูผลลัพธ์
n8n จะเปรียบเทียบข้อมูล input กับข้อมูลที่เก็บไว้จากการรันก่อนหน้า เนื่องจากนี่เป็นการรันครั้งแรก n8n จะ process ข้อมูลทั้งหมดและแสดงในแท็บ Kept ลำดับอาจไม่ตรงกับ input:
id | name | job | last_updated |
---|---|---|---|
1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
4 | Bruno Mars | Singer-songwriter | 2024-08-25T17:45:12.493Z |
5 | Billie Eilish | Singer-songwriter | 2024-09-10T09:30:12.493Z |
6 | Katy Perry | Pop star | 2024-10-08T12:30:45.493Z |
7 | Lady Gaga | Pop star | 2024-09-15T14:45:30.493Z |
8 | Rihanna | Pop star | 2024-10-01T11:50:22.493Z |
Items are only compared against previous executions
ข้อมูล input จะถูกเปรียบเทียบกับข้อมูลที่เก็บไว้จากการรันก่อนหน้าเท่านั้น หมายความว่าข้อมูลที่ซ้ำกันใน input เดียวกันจะไม่ถูกลบในโหมดนี้ ถ้าต้องการลบทั้งข้อมูลซ้ำใน input และข้าม execution ให้เชื่อมต่อ Remove Duplicate node สองตัวต่อกัน โดยตัวแรกใช้ Remove Items Repated Within Current Input และตัวที่สองใช้ Remove Items Processed in Previous Executions
- เปิด Code node แล้ว uncomment (ลบ
//
) บรรทัด "Tom Hanks" - บน canvas เลือก Test workflow อีกครั้ง แล้วเปิด Remove Duplicates node เพื่อดูผลลัพธ์
n8n จะเปรียบเทียบข้อมูล input กับข้อมูลที่เก็บไว้จากการรันก่อนหน้า คราวนี้แท็บ Kept จะมีแค่ record ใหม่จาก Code node:
id | name | job | last_updated |
---|---|---|---|
9 | Tom Hanks | Actor | 2024-10-17T13:58:31.493Z |
แท็บ Discarded จะมีข้อมูลที่ process ไปแล้วจากการรันก่อนหน้า:
id | name | job | last_updated |
---|---|---|---|
1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
4 | Bruno Mars | Singer-songwriter | 2024-08-25T17:45:12.493Z |
5 | Billie Eilish | Singer-songwriter | 2024-09-10T09:30:12.493Z |
6 | Katy Perry | Pop star | 2024-10-08T12:30:45.493Z |
7 | Lady Gaga | Pop star | 2024-09-15T14:45:30.493Z |
8 | Rihanna | Pop star | 2024-10-01T11:50:22.493Z |
ก่อนจะไปตัวอย่างถัดไป ให้เคลียร์ประวัติการ dedupe:
- เปิด Remove Duplicates node แล้วตั้งค่า Operation เป็น Clear Deduplication History
- กด Test step เพื่อเคลียร์ประวัติ dedupe
Keep items where the value is higher than any previous value#
- เปิด Remove Duplicates node แล้วตั้งค่า Operation เป็น Remove Items Processed in Previous Executions
- ตั้งค่า Keep Items Where เป็น Value Is Higher than Any Previous Value
- ตั้งค่า Value to Dedupe On เป็น
{{ $json.id }}
- บน canvas เลือก Test workflow เพื่อรัน workflow แล้วเปิด Remove Duplicates node เพื่อดูผลลัพธ์
n8n จะเปรียบเทียบข้อมูล input กับข้อมูลที่เก็บไว้จากการรันก่อนหน้า เนื่องจากเพิ่งเคลียร์ประวัติ n8n จะ process ข้อมูลทั้งหมดและแสดงในแท็บ Kept ลำดับอาจไม่ตรงกับ input:
id | name | job | last_updated |
---|---|---|---|
1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
4 | Bruno Mars | Singer-songwriter | 2024-08-25T17:45:12.493Z |
5 | Billie Eilish | Singer-songwriter | 2024-09-10T09:30:12.493Z |
6 | Katy Perry | Pop star | 2024-10-08T12:30:45.493Z |
7 | Lady Gaga | Pop star | 2024-09-15T14:45:30.493Z |
8 | Rihanna | Pop star | 2024-10-01T11:50:22.493Z |
9 | Tom Hanks | Actor | 2024-10-17T13:58:31.493Z |
- เปิด Code node แล้ว uncomment (ลบ
//
) บรรทัด "Madonna" และ "Bob Dylan" - บน canvas เลือก Test workflow อีกครั้ง แล้วเปิด Remove Duplicates node เพื่อดูผลลัพธ์
n8n จะเปรียบเทียบข้อมูล input กับข้อมูลที่เก็บไว้จากการรันก่อนหน้า คราวนี้แท็บ Kept จะมีแค่ "Bob Dylan" เพราะค่า id
(15) สูงกว่าค่าสูงสุดก่อนหน้า (9):
id | name | job | last_updated |
---|---|---|---|
15 | Bob Dylan | Folk singer | 2024-09-24T08:03:16.493Z |
แท็บ Discarded จะมีข้อมูล 13 รายการที่ค่า id
เท่ากับหรือน้อยกว่าค่าสูงสุดก่อนหน้า (9) แม้ "Madonna" จะเป็นข้อมูลใหม่แต่ id
ไม่สูงกว่าเดิม:
id | name | job | last_updated |
---|---|---|---|
0 | Madonna | Pop star | 2024-10-17T17:11:38.493Z |
1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
4 | Bruno Mars | Singer-songwriter | 2024-08-25T17:45:12.493Z |
5 | Billie Eilish | Singer-songwriter | 2024-09-10T09:30:12.493Z |
6 | Katy Perry | Pop star | 2024-10-08T12:30:45.493Z |
7 | Lady Gaga | Pop star | 2024-09-15T14:45:30.493Z |
8 | Rihanna | Pop star | 2024-10-01T11:50:22.493Z |
9 | Tom Hanks | Actor | 2024-10-17T13:58:31.493Z |
ก่อนจะไปตัวอย่างถัดไป ให้เคลียร์ประวัติการ dedupe:
- เปิด Remove Duplicates node แล้วตั้งค่า Operation เป็น Clear Deduplication History
- กด Test step เพื่อเคลียร์ประวัติ dedupe
Keep items where the value is a date later than any previous date#
- เปิด Remove Duplicates node แล้วตั้งค่า Operation เป็น Remove Items Processed in Previous Executions
- ตั้งค่า Keep Items Where เป็น Value Is a Date Later than Any Previous Date
- ตั้งค่า Value to Dedupe On เป็น
{{ $json.last_updated }}
- บน canvas เลือก Test workflow เพื่อรัน workflow แล้วเปิด Remove Duplicates node เพื่อดูผลลัพธ์
n8n จะเปรียบเทียบข้อมูล input กับข้อมูลที่เก็บไว้จากการรันก่อนหน้า เนื่องจากเพิ่งเคลียร์ประวัติ n8n จะ process ข้อมูลทั้งหมดและแสดงในแท็บ Kept ลำดับอาจไม่ตรงกับ input:
id | name | job | last_updated |
---|---|---|---|
0 | Madonna | Pop star | 2024-10-17T17:11:38.493Z |
1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
4 | Bruno Mars | Singer-songwriter | 2024-08-25T17:45:12.493Z |
5 | Billie Eilish | Singer-songwriter | 2024-09-10T09:30:12.493Z |
6 | Katy Perry | Pop star | 2024-10-08T12:30:45.493Z |
7 | Lady Gaga | Pop star | 2024-09-15T14:45:30.493Z |
8 | Rihanna | Pop star | 2024-10-01T11:50:22.493Z |
9 | Tom Hanks | Actor | 2024-10-17T13:58:31.493Z |
15 | Bob Dylan | Folk singer | 2024-09-24T08:03:16.493Z |
- เปิด Code node แล้ว uncomment (ลบ
//
) บรรทัด "Harry Nilsson" และ "Kylie Minogue"
- บน canvas เลือก Test workflow อีกครั้ง แล้วเปิด Remove Duplicates node เพื่อดูผลลัพธ์
n8n จะเปรียบเทียบข้อมูล input กับข้อมูลที่เก็บไว้จากการรันก่อนหน้า คราวนี้แท็บ Kept จะมีแค่ "Kylie Minogue" เพราะค่า last_updated
(2024-10-24T08:03:16.493Z
) ใหม่กว่าค่าสูงสุดก่อนหน้า (2024-10-17T17:11:38.493Z
):
id | name | job | last_updated |
---|---|---|---|
11 | Kylie Minogue | Pop star | 2024-10-24T08:03:16.493Z |
แท็บ Discarded จะมีข้อมูล 15 รายการที่ค่า last_updated
เท่ากับหรือน้อยกว่าค่าสูงสุดก่อนหน้า (2024-10-17T17:11:38.493Z
) แม้ "Harry Nilsson" จะเป็นข้อมูลใหม่แต่ last_updated
ไม่ใหม่กว่าเดิม:
id | name | job | last_updated |
---|---|---|---|
10 | Harry Nilsson | Singer-songwriter | 2020-10-17T17:11:38.493Z |
0 | Madonna | Pop star | 2024-10-17T17:11:38.493Z |
1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
1 | Taylor Swift | Pop star | 2024-09-20T10:12:43.493Z |
2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
2 | Ed Sheeran | Singer-songwriter | 2024-10-05T08:30:59.493Z |
3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
3 | Adele | Singer-songwriter | 2024-10-07T14:15:59.493Z |
4 | Bruno Mars | Singer-songwriter | 2024-08-25T17:45:12.493Z |
5 | Billie Eilish | Singer-songwriter | 2024-09-10T09:30:12.493Z |
6 | Katy Perry | Pop star | 2024-10-08T12:30:45.493Z |
7 | Lady Gaga | Pop star | 2024-09-15T14:45:30.493Z |
8 | Rihanna | Pop star | 2024-10-01T11:50:22.493Z |
9 | Tom Hanks | Actor | 2024-10-17T13:58:31.493Z |
15 | Bob Dylan | Folk singer | 2024-09-24T08:03:16.493Z |