แชร์ทรัพยากรกับพนักงานใหม่
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ระดับการเขียนโค้ด: ผู้เริ่มต้น
ระยะเวลา: 20 นาที
ประเภทโปรเจ็กต์: การทำงานอัตโนมัติด้วยทริกเกอร์ที่อิงตามเหตุการณ์
วัตถุประสงค์
- ทำความเข้าใจว่าโซลูชันทำอะไรได้บ้าง
- ทำความเข้าใจสิ่งที่บริการ Apps Script ทำภายในโซลูชัน
- ตั้งค่าสคริปต์
- เรียกใช้สคริปต์
เกี่ยวกับโซลูชันนี้
สำคัญ: คุณต้องเป็นผู้ดูแลระบบ Google Workspace จึงจะใช้โซลูชันนี้ได้
แชร์แหล่งข้อมูลกับพนักงานใหม่ได้ในขั้นตอนเดียว โซลูชันนี้ใช้แบบฟอร์ม
ใน Google ฟอร์มเพื่อเพิ่มพนักงานใหม่ลงในกลุ่มใน Google Groups การแชร์
ทรัพยากรกับที่อยู่ของกลุ่มดังกล่าวจะช่วยให้คุณให้สิทธิ์เข้าถึง
ทรัพยากรที่พนักงานใหม่ต้องการได้อย่างง่ายดาย
หากมีสิทธิ์เพิ่มผู้ใช้ลงในกลุ่ม คุณจะใช้โซลูชันนี้เพื่อ
กระจายความรับผิดชอบไปยังสมาชิกคนอื่นๆ ในทีมได้ เมื่อผู้ใช้ส่งแบบฟอร์ม ทริกเกอร์ที่อิงตามเหตุการณ์จะเรียกใช้สคริปต์ในฐานะคุณและเพิ่มอีเมลของบุคคลใหม่ลงในกลุ่ม
คุณเลือกเปิดการแจ้งเตือนเพื่อรับอีเมลทุกครั้งที่มีคน
ส่งแบบฟอร์มได้

วิธีการทำงาน
เมื่อมีผู้ส่งแบบฟอร์มพร้อมอีเมลของผู้ใช้และกลุ่มที่ควรเพิ่มผู้ใช้
เข้าไป สคริปต์จะตรวจสอบว่าบุคคลนั้นเป็นสมาชิกของกลุ่มดังกล่าวอยู่แล้วหรือไม่
หากมี ผู้ใช้จะได้รับอีเมลยืนยันว่าตนอยู่ในกลุ่มแล้ว มิเช่นนั้น สคริปต์จะเพิ่มผู้ใช้ลงในกลุ่มและส่ง
อีเมลต้อนรับให้
บริการ Apps Script
โซลูชันนี้ใช้บริการต่อไปนี้
- บริการสคริปต์ - สร้างทริกเกอร์ที่
เรียกใช้สคริปต์ทุกครั้งที่มีผู้ส่งแบบฟอร์ม
- บริการกลุ่ม - ตรวจสอบว่าอีเมลที่ส่งในแบบฟอร์มเป็นสมาชิกของกลุ่มอยู่แล้วหรือไม่
- บริการขั้นสูงของ Admin SDK Directory - เพิ่ม
อีเมลที่ส่งในแบบฟอร์มไปยังกลุ่ม
- บริการอีเมล - ส่งอีเมลไปยังอีเมล
ที่อยู่ที่ส่งในแบบฟอร์มเพื่อยืนยันการเป็นสมาชิกกลุ่มหรือ
ต้อนรับสมาชิกใหม่เข้าสู่กลุ่ม
- บริการสเปรดชีต - เพิ่มสถานะของผู้ใช้
ลงในสเปรดชีตคำตอบของแบบฟอร์ม สถานะจะเป็นอยู่ในกลุ่มแล้วหรือเพิ่มใหม่
- บริการเรียก URL - เรียกเอกสาร Google เอกสาร
เป็นสตริง HTML เอกสารมีเนื้อหาของอีเมล
ที่สคริปต์ส่ง
ข้อกำหนดเบื้องต้น
ตั้งค่าสคริปต์
คลิกปุ่มต่อไปนี้เพื่อคัดลอกสเปรดชีตแชร์แหล่งข้อมูลกับพนักงานใหม่
โปรเจ็กต์ Apps Script
สำหรับโซลูชันนี้แนบอยู่กับสเปรดชีต
ทำสำเนา
คลิกส่วนขยาย > Apps Script
ตรวจสอบว่าบริการ AdminDirectory อยู่ในส่วนบริการ
หากมี ให้ข้ามไปยังขั้นตอนที่ 6 หากไม่ ให้ทำตามขั้นตอนถัดไป
คลิกเพิ่มบริการ add ข้างบริการ
ในกล่องโต้ตอบ ให้เลือก Admin SDK API แล้วคลิกเพิ่ม
เลือก installTrigger ในเมนูฟังก์ชันแบบเลื่อนลง
คลิกเรียกใช้
ให้สิทธิ์สคริปต์เมื่อได้รับข้อความแจ้ง
หากหน้าจอคำยินยอมของ OAuth แสดงคำเตือนว่า แอปนี้ยังไม่ได้รับการยืนยัน
ให้ดำเนินการต่อโดยเลือกขั้นสูง >
ไปที่ {ชื่อโปรเจ็กต์} (ไม่ปลอดภัย)
สำคัญ: หากเรียกใช้ฟังก์ชันนี้มากกว่า 1 ครั้ง ระบบจะสร้างทริกเกอร์หลายรายการและส่งอีเมลที่ซ้ำกัน หากต้องการลบทริกเกอร์เพิ่มเติม ให้ทำตาม
ขั้นตอนต่อไปนี้
- คลิกทริกเกอร์

- คลิกเพิ่มเติมข้างทริกเกอร์
> ลบทริกเกอร์
เรียกใช้สคริปต์
- กลับไปที่สเปรดชีต แล้วคลิกเครื่องมือ
> จัดการแบบฟอร์ม
> ไปที่แบบฟอร์มที่ใช้งานจริง
- กรอกแบบฟอร์มด้วยอีเมลและกลุ่มที่คุณมีสิทธิ์จัดการการเป็นสมาชิก แล้วคลิกส่ง
- กลับไปที่สเปรดชีตและดูรายการแบบฟอร์ม คอลัมน์สถานะจะแสดง
ว่ามีการเพิ่มอีเมลของคุณลงในกลุ่มหรือคุณเป็นสมาชิกของกลุ่มอยู่แล้ว
- ตรวจสอบอีเมลเพื่อดูอีเมลต้อนรับหรือการยืนยันการเป็นสมาชิกกลุ่ม
ผู้ร่วมให้ข้อมูล
ตัวอย่างนี้ได้รับการดูแลโดย Google โดยได้รับความช่วยเหลือจาก Google Developer Expert
ขั้นตอนถัดไป
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\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)"]]