與新進員工共用資源
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
程式設計程度:初學者
所需時間:20 分鐘
專案類型:使用事件驅動觸發條件進行自動化
目標
- 瞭解解決方案的功能。
- 瞭解解決方案中的 Apps Script 服務功能。
- 設定指令碼。
- 執行指令碼。
認識這項解決方案
重要事項:您必須是 Google Workspace 管理員,才能使用這項解決方案。
只要一個步驟,即可與新進員工分享資源。這項解決方案會使用 Google 表單中的表單,將新員工新增至 Google 網路論壇中的群組。只要將資源分享給該群組的地址,就能輕鬆授予新進員工所需資源的存取權。
如果您有權限將使用者新增至群組,可以使用這項解決方案將責任分配給其他團隊成員。使用者提交表單時,事件觸發條件會以您的身分執行指令碼,並將新成員的電子郵件地址新增至群組。
你也可以視需要開啟通知,在有人提交表單時收到電子郵件。

運作方式
當有人提交表單,並提供使用者的電子郵件地址和應加入的群組時,指令碼會檢查該使用者是否已是該群組的成員。如果使用者已是群組成員,系統會傳送電子郵件給對方,確認他們已加入群組。否則,指令碼會將使用者加入群組,並傳送歡迎電子郵件給對方。
Apps Script 服務
這項解決方案會使用下列服務:
- 指令碼服務:建立觸發條件,在有人提交表單時啟動指令碼。
- 群組服務:檢查表單上提交的電子郵件是否已是群組成員。
- Admin SDK Directory 進階服務:將表單中提交的電子郵件地址新增至群組。
- 郵件服務:將電子郵件傳送至表單上提交的電子郵件地址,確認使用者是否為群組成員,或歡迎使用者加入群組。
- 試算表服務:將使用者的狀態新增至表單回覆試算表。狀態為「已在群組中」或「新加入」。
- 網址擷取服務:以 HTML 字串形式擷取 Google 文件。這份文件包含指令碼傳送的電子郵件內容。
必要條件
設定指令碼
按一下下列按鈕,複製「Share resources with new hires」(與新進員工分享資源)試算表。這個解決方案的 Apps Script 專案會附加至試算表。
建立副本
依序點選「擴充功能」>「Apps Script」。
在「服務」下方,確認「AdminDirectory」服務已列出。如果是,請跳到步驟 6。如果不是,請繼續下一個步驟。
按一下「服務」旁的「新增服務」圖示 add。
在對話方塊中,選取「Admin SDK API」,然後按一下「新增」。
在函式下拉式選單中,選取「installTrigger」installTrigger。
按一下「執行」。
出現提示訊息時,請授權執行指令碼。如果 OAuth 同意畫面顯示「這個應用程式未經驗證」警告,請依序選取「進階」>「前往『{專案名稱}』(不安全)」,繼續操作。
重要事項:如果多次執行這項函式,系統會產生多個觸發條件,並傳送重複的電子郵件。如要刪除額外觸發條件,請按照下列步驟操作:
- 按一下「觸發條件」
。
- 依序點選觸發條件旁的「更多」圖示
>「刪除觸發條件」。
執行指令碼
- 返回試算表,然後依序點選「工具」>「管理表單」>「前往即時表單」。
- 在表單中填寫電子郵件地址,以及您有權管理成員的群組,然後按一下「提交」。
- 返回試算表,查看表單項目。狀態欄會顯示您的電子郵件地址是否已加入群組,或是否已是群組成員。
- 檢查電子郵件,看看是否收到歡迎電子郵件或群組成員資格確認信。
貢獻者
這個範例由 Google 維護,並由 Google 開發人員專家協助。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eThis solution allows Google Workspace administrators to easily share resources with new employees by automatically adding them to a Google Group.\u003c/p\u003e\n"],["\u003cp\u003eThe script uses an event-driven trigger to add new employees to a group when their information is submitted via a Google Form.\u003c/p\u003e\n"],["\u003cp\u003eThe script utilizes various Apps Script services including Groups, Admin SDK Directory, Mail, and Spreadsheet to manage group memberships and communicate with users.\u003c/p\u003e\n"],["\u003cp\u003eSetup requires copying a spreadsheet, enabling the AdminDirectory service, and authorizing the script to run.\u003c/p\u003e\n"],["\u003cp\u003eRunning the script involves submitting a form with the new employee's email and desired group, triggering the automatic addition and email notifications.\u003c/p\u003e\n"]]],["This solution automates sharing resources with new hires using Google Workspace. It utilizes a Google Form submission to trigger a script that adds new employees to a specified Google Group. The script checks for existing membership, adds the user if necessary, and sends either a welcome or confirmation email. It leverages Apps Script services, including Script, Groups, Admin SDK Directory, Mail, Spreadsheet, and URL Fetch to manage triggers, check group membership, add users, send emails, and update form response spreadsheet with user status.\n"],null,["# Share resources with new hires\n\n**Coding level** : Beginner \n\n**Duration** : 20 minutes \n\n**Project type** : Automation with an [event-driven trigger](/apps-script/guides/triggers/installable#event-driven_triggers)\n\nObjectives\n----------\n\n- Understand what the solution does.\n- Understand what the Apps Script services do within the solution.\n- Set up the script.\n- Run the script.\n\nAbout this solution\n-------------------\n\n**Important**: You must be a Google Workspace Administrator to use this\nsolution.\n\nShare resources with incoming employees in one step. This solution uses a form\nin Google Forms to add new employees to a group in Google Groups. By sharing\nresources with that group's address, you can easily give new hires access to the\nresources they need.\n\nIf you have permission to add users to a group, you can use this solution to\ndistribute the responsibility to other members of your team. When they submit\nthe form, the event-driven trigger runs the script as you and adds the new\nperson's email to the group.\n\nOptionally, you can turn on notifications to [get an email every time someone\nsubmits the form](https://support.google.com/a/users/answer/9308874).\n\n### How it works\n\nWhen someone submits a form with a user's email and the group the user should be\nadded to, the script checks whether or not the person already belongs to that\ngroup. If they do, the user receives an email confirming that they're already in\nthe group. Otherwise, the script adds the user to the group and sends them a\nwelcome email.\n\n### Apps Script services\n\nThis solution uses the following services:\n\n- [Script service](/apps-script/reference/script)--Creates the trigger that fires the script each time someone submits a form.\n- [Groups service](/apps-script/reference/groups)--Checks whether the email submitted on the form is already a member of the group.\n- [Admin SDK Directory advanced service](/apps-script/advanced/admin-sdk-directory)--Adds the email submitted on the form to the group.\n- [Mail service](/apps-script/reference/mail)--Sends an email to the email address submitted on the form to either confirm their group membership or welcome them to the group.\n- [Spreadsheet service](/apps-script/reference/spreadsheet)--Adds the user's status to the form responses spreadsheet. The status is either **Already in\n group** or **Newly added**.\n- [URL Fetch service](/apps-script/reference/url-fetch)--Fetches a Google Docs document as an HTML string. The document contains the content of the email that the script sends.\n\nPrerequisites\n-------------\n\n- A [Google Workspace account](https://workspace.google.com/features/)\n- You must be a Google Workspace Administrator\n\nSet up the script\n-----------------\n\n1. Click the following button to copy the **Share resources with new hires**\n spreadsheet. The Apps Script\n project for this solution is attached to the spreadsheet.\n\n [Make a copy](https://docs.google.com/spreadsheets/d/1IK9nIanIOxInnvUtaY9lsXHAqokkA9xqcC43VRxQ-fo/copy?usp=sharing)\n\n2. Click **Extensions** \\\u003e **Apps Script**.\n\n3. Under **Services** , make sure the **AdminDirectory** service is\n listed. If it is, skip to step 6. If it's not, continue to the next step.\n\n4. Next to **Services** , click Add a service add.\n\n5. In the dialog, select **Admin SDK API** and click **Add**.\n\n6. In the function dropdown, select **installTrigger**.\n\n7. Click **Run**.\n\n8. When prompted, authorize the script.\n If the OAuth consent screen displays the warning, **This app isn't verified** ,\n continue by selecting **Advanced** \\\u003e\n **Go to {Project Name} (unsafe)**.\n\n**Important**: If you run this function more than once, it generates multiple\ntriggers and will send duplicate emails. To delete extra triggers, take the\nfollowing steps:\n\n1. Click **Triggers** .\n2. Next to the trigger, click More \\\u003e **Delete trigger**.\n\nRun the script\n--------------\n\n1. Return to the spreadsheet and click **Tools** \\\u003e **Manage form** \\\u003e **Go to live form**.\n2. Fill out the form with your email address and a group that you have permission to manage the membership for and click **Submit**.\n3. Return to the spreadsheet and view the form entry. The status column shows whether your email address was added to or already a member of the group.\n4. Check your email for either a welcome email or confirmation of your group membership.\n\nContributors\n------------\n\nThis sample is maintained by Google with the help of Google Developer Experts.\n\nNext steps\n----------\n\n- [Event-driven triggers](/apps-script/guides/triggers/installable#event-driven_triggers)\n- [Extend Google Sheets](/apps-script/guides/sheets)"]]