Skip to content

If#

ใช้ If node เพื่อแยก workflow ตามเงื่อนไขที่กำหนดโดยใช้การเปรียบเทียบ

Add conditions#

สร้าง Conditions สำหรับเปรียบเทียบใน If node

  • ใช้ dropdown เลือก data type และประเภทการเปรียบเทียบสำหรับเงื่อนไข เช่น ถ้าต้องการกรองวันที่ที่หลังจากวันที่ที่กำหนด ให้เลือก Date & Time > is after
  • ช่องกรอกข้อมูลและค่าที่ต้องใส่ในเงื่อนไขจะเปลี่ยนไปตาม data type และการเปรียบเทียบที่เลือก ดูรายละเอียดเพิ่มเติมได้ที่ Available data type comparisons สำหรับรายการเปรียบเทียบทั้งหมดในแต่ละ data type

เลือก Add condition เพื่อเพิ่มเงื่อนไขใหม่

Combining conditions#

คุณสามารถเลือกได้ว่าจะเก็บข้อมูลไว้เมื่อ:

  • ตรงตามทุกเงื่อนไข: สร้างเงื่อนไขสองข้อขึ้นไปแล้วเลือก AND ใน dropdown ระหว่างเงื่อนไข
  • ตรงตามเงื่อนไขใดเงื่อนไขหนึ่ง: สร้างเงื่อนไขสองข้อขึ้นไปแล้วเลือก OR ใน dropdown ระหว่างเงื่อนไข

Templates and examples#

AI agent that can scrape webpages

by Eduard

View template details
Pulling data from services that n8n doesn’t have a pre-built integration for

by Jonathan

View template details
✨🤖Automate Multi-Platform Social Media Content Creation with AI

by Joseph LePage

View template details
Browse เงื่อนไข (If) integration templates, or search all templates

Branch execution with If and Merge nodes#

0.236.0 และต่ำกว่า

n8n ได้ลบพฤติกรรมการ execution นี้ในเวอร์ชัน 1.0 ส่วนนี้ใช้กับ workflows ที่ใช้ลำดับการ execution แบบ v0 (legacy) โดยค่าเริ่มต้น นี่คือ workflows ทั้งหมดที่สร้างก่อนเวอร์ชัน 1.0 คุณสามารถเปลี่ยนลำดับการ execution ได้ใน workflow settings

หากคุณเพิ่ม Merge node ไปยัง workflow ที่มี If node อาจส่งผลให้ data streams ทั้งสองของ If node ทำงาน

Data stream หนึ่งจะ trigger Merge node ซึ่งจากนั้นจะไป execute data stream อีกอัน

ตัวอย่างเช่น ในภาพหน้าจอด้านล่าง มี workflow ที่มี Edit Fields node, If node และ Merge node พฤติกรรมมาตรฐานของ If node คือการ execute data stream เดียว (ในภาพหน้าจอคือ output true) อย่างไรก็ตาม เนื่องจากมี Merge node ทำให้ data streams ทั้งสองทำงาน แม้ว่า If node จะไม่ได้ส่งข้อมูลใดๆ ไปยัง data stream false ก็ตาม

Screenshot of a workflow. The workflow has an Edit Fields node, followed by an If node. It ends with a Merge node.

ดูข้อมูลเพิ่มเติมเกี่ยวกับการใช้เงื่อนไขเพื่อสร้าง logic ที่ซับซ้อนใน n8n ได้ที่ Splitting with conditionals

ถ้าต้องการ output มากกว่าสองทาง ให้ใช้ Switch node

การเปรียบเทียบประเภทข้อมูลที่มีอยู่#

String#

ประเภทข้อมูล String รองรับการเปรียบเทียบเหล่านี้:

  • exists
  • does not exist
  • is empty
  • is not empty
  • is equal to
  • is not equal to
  • contains
  • does not contain
  • starts with
  • does not start with
  • ends with
  • does not end with
  • matches regex
  • does not match regex

Number#

ประเภทข้อมูล Number รองรับการเปรียบเทียบเหล่านี้:

  • exists
  • does not exist
  • is empty
  • is not empty
  • is equal to
  • is not equal to
  • is greater than
  • is less than
  • is greater than or equal to
  • is less than or equal to

Date & Time#

ประเภทข้อมูล Date & Time รองรับการเปรียบเทียบเหล่านี้:

  • exists
  • does not exist
  • is empty
  • is not empty
  • is equal to
  • is not equal to
  • is after
  • is before
  • is after or equal to
  • is before or equal to

Boolean#

ประเภทข้อมูล Boolean รองรับการเปรียบเทียบเหล่านี้:

  • exists
  • does not exist
  • is empty
  • is not empty
  • is true
  • is false
  • is equal to
  • is not equal to

Array#

ประเภทข้อมูล Array รองรับการเปรียบเทียบเหล่านี้:

  • exists
  • does not exist
  • is empty
  • is not empty
  • contains
  • does not contain
  • length equal to
  • length not equal to
  • length greater than
  • length less than
  • length greater than or equal to
  • length less than or equal to

Object#

ประเภทข้อมูล Object รองรับการเปรียบเทียบเหล่านี้:

  • exists
  • does not exist
  • is empty
  • is not empty