Tetap teratur dengan koleksi Simpan dan kategorikan konten berdasarkan preferensi Anda.
Pemicu Apps Script menyebabkan fungsi skrip tertentu (fungsi pemicu) dieksekusi setiap kali peristiwa tertentu terjadi. Hanya peristiwa tertentu yang dapat menyebabkan pemicu diaktifkan, dan setiap aplikasi Google Workspace mendukung serangkaian peristiwa yang berbeda.
Saat pemicu diaktifkan, objek peristiwa akan dibuat. Struktur JSON ini berisi detail tentang peristiwa yang terjadi. Informasi dalam struktur objek peristiwa diatur secara berbeda berdasarkan jenis pemicu.
Setelah objek peristiwa dibuat, Apps Script akan meneruskannya sebagai parameter ke fungsi pemicu. Fungsi pemicu adalah fungsi callback yang harus Anda implementasikan sendiri, untuk melakukan tindakan apa pun yang sesuai untuk merespons peristiwa. Misalnya, di add-on Google Workspace yang memperluas Gmail, Anda dapat menentukan pemicu yang membuat antarmuka kartu baru saat pengguna membuka rangkaian pesan. Dalam hal ini, Anda menerapkan fungsi callback kontekstual untuk membuat kartu yang membentuk UI baru menggunakan data yang diteruskan dalam objek peristiwa.
Halaman ini memberikan panduan tentang penggunaan pemicu dalam project add-on Google Workspace.
Pemicu manifes
Tidak seperti add-on Editor, add-on Google Workspace saat ini tidak dapat menggunakan pemicu sederhana Apps Script. Sebagai gantinya, add-on tersebut menggunakan pemicu yang dirancang khusus untuk add-on Google Workspace: pemicu manifes.
Pemicu manifes ditentukan sepenuhnya dalam manifes add-on Google Workspace. Contoh pemicu manifes meliputi berikut ini:
Pemicu halaman beranda yang membangun dan menampilkan halaman beranda add-on.
Pemicu pembukaan acara Kalender yang menampilkan kartu baru atau melakukan tindakan lain saat acara Kalender dibuka.
Pemicu update acara Kalender yang menampilkan kartu baru atau melakukan tindakan lain saat pengguna mengedit dan menyimpan acara Kalender.
Pemicu Drive onItemsSelected yang menampilkan kartu baru atau melakukan tindakan lain saat pengguna memilih satu atau beberapa file atau folder di Drive.
Pemicu tulis Gmail yang menampilkan kartu add-on saat pengguna membuka add-on di jendela tulis Gmail.
Pemicu kontekstual Gmail yang menampilkan kartu baru atau melakukan tindakan lain saat pengguna membuka pesan Gmail.
Pemicu Editor onFileScopeGranted yang menampilkan kartu baru saat pengguna memberikan otorisasi untuk cakupan OAuth drive.file dalam dokumen Editor saat ini.
Dalam daftar di atas, hanya pemicu halaman beranda yang non-kontekstual; sisanya adalah pemicu kontekstual. Lihat Manifes untuk mengetahui informasi selengkapnya tentang definisi pemicu manifes.
Selain pemicu manifes, add-on Google Workspace juga dapat menggunakan pemicu yang dapat diinstal Apps Script.
Pembatasan
Pemicu manifes memiliki batasan tertentu dalam penggunaannya.
Pemicu ini hanya digunakan dalam project add-on Google Workspace; pemicu ini tidak memiliki tujuan dalam aplikasi lain.
Karena ditentukan dalam manifes add-on dan bukan dalam kodenya, Anda tidak dapat menggunakan layanan Script Apps Script untuk membuat atau mengubah pemicu ini.
Pemicu kontekstual Gmail saat ini hanya dapat memiliki kriteria unconditional. Artinya, pemicu kontekstual diaktifkan untuk setiap pesan email, terlepas dari kontennya.
Setiap add-on hanya dapat memiliki satu pemicu dari setiap jenis, per pengguna, per dokumen.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-31 UTC."],[[["\u003cp\u003eApps Script triggers execute a specific function when a defined event occurs within a Google Workspace application.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Workspace add-ons utilize manifest triggers, defined in the add-on's manifest, to respond to events like opening a document or composing an email.\u003c/p\u003e\n"],["\u003cp\u003eManifest triggers can be contextual, reacting to specific user actions within a document or application, or non-contextual, like those that build the add-on's homepage.\u003c/p\u003e\n"],["\u003cp\u003eWhile manifest triggers offer event-driven functionality, they have limitations, including restrictions on their use and creation methods.\u003c/p\u003e\n"]]],["Apps Script triggers initiate a script function when specific events occur, creating an event object with event details. This object is then passed to a user-implemented trigger function, enabling actions based on the event. Google Workspace add-ons use manifest triggers, defined in the add-on's manifest, to trigger actions like displaying cards on homepage, when opening/updating Calendar events, selecting Drive items, or opening a message in Gmail. Contextual triggers and installable triggers are also supported but with some restrictions.\n"],null,["[Apps Script triggers](/apps-script/guides/triggers) cause a specified script\nfunction (the *trigger function*) to execute whenever a specified event\noccurs. Only certain events can cause triggers to fire, and each\nGoogle Workspace application supports a different set of events.\n\nWhen a trigger fires, an *event object* is created. This JSON structure\ncontains details about the event that occurred. The information in the event\nobject structure is organized differently based on the trigger type.\n\nOnce the event object is created, Apps Script passes it as a parameter to the\ntrigger function. The trigger function is a callback function that you must\nimplement yourself, to take whatever actions are appropriate to respond to the\nevent. For example, in a\nGoogle Workspace add-on that extends Gmail, you can\ndefine a trigger that creates a new card interface when the user opens a message\nthread. In this case, you implement a contextual callback function to create\nthe cards making up the new UI using the data passed in the\n[event object](/workspace/add-ons/concepts/event-objects).\n\nThis page provides guidelines on using triggers in\nGoogle Workspace\nadd-on projects.\n\nManifest triggers\n\nUnlike Editor add-ons, Google Workspace add-ons\ncurrently can't use Apps Script [simple triggers](/apps-script/guides/triggers)\nInstead, they use triggers designed specifically for\nGoogle Workspace add-ons: *manifest triggers*.\n\nManifest triggers are defined completely in the\nGoogle Workspace add-on's\n[manifest](/workspace/add-ons/concepts/workspace-manifests). Examples of manifest triggers include the\nfollowing:\n\n- **Homepage triggers** that build and display the add-on homepage.\n- **Calendar eventOpen triggers** that display a new card or take other actions when a Calendar event is opened.\n- **Calendar eventUpdate triggers** that display a new card or take other actions when a user edits and saves a Calendar event.\n- **Drive onItemsSelected triggers** that display a new card or take other actions when a user selects one or more files or folders in Drive.\n- **Gmail compose triggers** that display an add-on card when the user opens the add-on in the Gmail compose window.\n- **Gmail contextual triggers** that display a new card or take other actions when the user opens a Gmail message.\n- **Editor onFileScopeGranted triggers** that display a new card when users grant authorization for the `drive.file` OAuth scope in the current Editor document.\n\nIn the above list, only homepage triggers are non-contextual; the rest are\ncontextual triggers. See [Manifest](/workspace/add-ons/concepts/workspace-manifests)\nfor more information about manifest trigger definitions.\n\nIn addition to manifest triggers, Google Workspace\nadd-ons can also use Apps Script\n[installable triggers](/apps-script/guides/triggers/installable).\n\nRestrictions\n\nManifest triggers have certain restrictions to their use.\n\n- These triggers are only used in Google Workspace add-on projects; they have no purpose in any other application.\n- Since they are defined in the add-on manifest and not in its code, you can't use the Apps Script [`Script`](/apps-script/reference/script) service to create or modify these triggers.\n- Gmail contextual triggers currently can only have an `unconditional` criteria. This means contextual triggers fire for every email message, regardless of content.\n- Each add-on can only have one trigger of each type, per user, per document."]]