Chia sẻ tài nguyên với nhân viên mới
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Cấp độ viết mã: Sơ cấp
Thời lượng: 20 phút
Loại dự án: Tự động hoá bằng trình kích hoạt dựa trên sự kiện
Mục tiêu
- Tìm hiểu chức năng của giải pháp.
- Tìm hiểu chức năng của các dịch vụ Apps Script trong giải pháp.
- Thiết lập tập lệnh.
- Chạy tập lệnh.
Giới thiệu về giải pháp này
Quan trọng: Bạn phải là Quản trị viên Google Workspace thì mới có thể sử dụng giải pháp này.
Chia sẻ tài nguyên với nhân viên mới chỉ trong một bước. Giải pháp này sử dụng một biểu mẫu trong Google Biểu mẫu để thêm nhân viên mới vào một nhóm trong Google Groups. Bằng cách chia sẻ tài nguyên với địa chỉ của nhóm đó, bạn có thể dễ dàng cấp cho nhân viên mới quyền truy cập vào các tài nguyên mà họ cần.
Nếu có quyền thêm người dùng vào một nhóm, bạn có thể sử dụng giải pháp này để phân công trách nhiệm cho các thành viên khác trong nhóm. Khi họ gửi biểu mẫu, trình kích hoạt dựa trên sự kiện sẽ chạy tập lệnh dưới dạng bạn và thêm email của người mới vào nhóm.
Bạn có thể bật thông báo để nhận email mỗi khi có người gửi biểu mẫu (không bắt buộc).

Cách hoạt động
Khi người dùng gửi biểu mẫu có email của người dùng và nhóm mà người dùng cần được thêm vào, tập lệnh sẽ kiểm tra xem người đó đã thuộc nhóm đó hay chưa. Nếu có, người dùng sẽ nhận được email xác nhận rằng họ đã có trong nhóm. Nếu không, tập lệnh sẽ thêm người dùng vào nhóm và gửi cho họ một email chào mừng.
Các dịch vụ của Apps Script
Giải pháp này sử dụng các dịch vụ sau:
- Dịch vụ tập lệnh – Tạo trình kích hoạt sẽ kích hoạt tập lệnh mỗi khi có người gửi biểu mẫu.
- Dịch vụ Nhóm – Kiểm tra xem email được gửi trên biểu mẫu đã là thành viên của nhóm hay chưa.
- Dịch vụ nâng cao Admin SDK Directory – Thêm email được gửi trên biểu mẫu vào nhóm.
- Dịch vụ gửi thư – Gửi email đến địa chỉ email được gửi trên biểu mẫu để xác nhận tư cách thành viên nhóm hoặc chào mừng họ tham gia nhóm.
- Dịch vụ bảng tính – Thêm trạng thái của người dùng vào bảng tính phản hồi của biểu mẫu. Trạng thái là Đã có trong nhóm hoặc Mới thêm.
- Dịch vụ tìm nạp URL – Tìm nạp một tài liệu trên Google Tài liệu dưới dạng chuỗi HTML. Tài liệu này chứa nội dung của email mà tập lệnh gửi.
Điều kiện tiên quyết
Thiết lập tập lệnh
Nhấp vào nút sau để sao chép bảng tính Chia sẻ tài nguyên với nhân viên mới. Dự án Apps Script cho giải pháp này được đính kèm vào bảng tính.
Tạo bản sao
Nhấp vào Tiện ích > Apps Script.
Trong mục Dịch vụ, hãy đảm bảo dịch vụ AdminDirectory có trong danh sách. Nếu có, hãy chuyển sang bước 6. Nếu không, hãy chuyển sang bước tiếp theo.
Bên cạnh Dịch vụ, hãy nhấp vào biểu tượng Thêm dịch vụ add.
Trong hộp thoại, hãy chọn Admin SDK API (API Admin SDK) rồi nhấp vào Add (Thêm).
Trong trình đơn thả xuống của hàm, hãy chọn installTrigger.
Nhấp vào Chạy.
Khi được nhắc, hãy cho phép tập lệnh chạy.
Nếu màn hình đồng ý OAuth hiển thị cảnh báo Ứng dụng này chưa được xác minh, hãy tiếp tục bằng cách chọn Nâng cao >
Chuyển đến {Tên dự án} (không an toàn).
Lưu ý quan trọng: Nếu bạn chạy hàm này nhiều lần, hàm sẽ tạo nhiều điều kiện kích hoạt và gửi email trùng lặp. Để xoá các điều kiện kích hoạt bổ sung, hãy làm theo các bước sau:
- Nhấp vào Trình kích hoạt
.
- Bên cạnh bộ khởi động, hãy nhấp vào biểu tượng Tuỳ chọn khác
> Xoá bộ khởi động.
Chạy tập lệnh
- Quay lại bảng tính rồi nhấp vào Công cụ
> Quản lý biểu mẫu
> Chuyển đến biểu mẫu trực tiếp.
- Điền địa chỉ email của bạn và một nhóm mà bạn có quyền quản lý thành viên vào biểu mẫu, rồi nhấp vào Gửi.
- Quay lại bảng tính và xem mục nhập trong biểu mẫu. Cột trạng thái cho biết địa chỉ email của bạn đã được thêm vào hay đã là thành viên của nhóm.
- Kiểm tra email của bạn để tìm email chào mừng hoặc email xác nhận tư cách thành viên nhóm.
Người đóng góp
Mẫu này do Google duy trì với sự trợ giúp của các Chuyên gia Google về phát triển.
Các bước tiếp theo
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-31 UTC.
[null,null,["Cập nhật lần gần đây nhất: 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)"]]