ROOM64 / KNOWLEDGE / ERPNEXT

Generate Item Code Based On Custom Logic

Add this Custom Script in the script of Item , so that the new Item Code isgenerated just before the Item gets saved.

อ่านต้นฉบับที่ ERPNext Official Docs ↗
เอกสารอ้างอิงภาษาอังกฤษเนื้อหาจากเอกสาร ERPNext คงรายละเอียดและโค้ดตามต้นฉบับ · ต้นฉบับอัปเดต 2026-03-02 ชื่อเมนูและ DocType ที่ใช้ได้ขึ้นอยู่กับเวอร์ชันและรุ่นที่ทีมใช้งาน

Projects · โครงการและงานบริการ · Generate Item Code Based On Custom Logic

Add this Custom Script in the script of Item , so that the new Item Code is
generated just before the Item gets saved.

 cur_frm.cscript.customvalidate = function (doc) {
  // clear itemcode (name is from itemcode)
  doc.itemcode = "";

  // first 2 characters based on itemgroup
  switch (doc.itemgroup) {
    case "Test A":
      doc.itemcode = "TA";
      break;
    case "Test B":
      doc.itemcode = "TB";
      break;
    default:
      doc.itemcode = "XX";
  }

  // add next 2 characters based on brand
  switch (doc.brand) {
    case "Brand A":
      doc.itemcode += "BA";
      break;
    case "Brand B":
      doc.itemcode += "BB";
      break;
    default:
      doc.itemcode += "BX";
  }
};
เนื้อหาเอกสารอ้างอิงและภาพประกอบมาจาก ERPNext / Frappe Official Docs · บทความแนะนำภาษาไทยเรียบเรียงโดย Room64 · เว็บไซต์นี้เป็นคู่มือประกอบการใช้งานโดย Room64 · เอกสารทางการ ↗

มีงานที่อยากให้ Software, AI หรือ Automation ช่วยอยู่ไหม?

เล่า workflow หรือปัญหาที่ทีมกำลังเจอ เราช่วยดูได้ว่าควรใช้ระบบสำเร็จรูป เชื่อมเครื่องมือเดิม หรือพัฒนาเพิ่มเฉพาะส่วนไหน

คุยกับเราทาง LINEhello@room64.net