与新员工分享资源
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
编码水平:初级
时长:20 分钟
项目类型:使用事件驱动型触发器实现自动化
目标
- 了解解决方案的功能。
- 了解 Apps 脚本服务在解决方案中的作用。
- 设置脚本。
- 运行脚本。
关于此解决方案
重要提示:您必须是 Google Workspace 管理员才能使用此解决方案。
一步到位地与新员工分享资源。此解决方案使用 Google 表单中的表单将新员工添加到 Google 群组中的群组。通过与该群组的地址共享资源,您可以轻松为新员工授予访问所需资源的权限。
如果您有权向群组添加用户,则可以使用此解决方案将责任分摊给团队的其他成员。当他们提交表单时,由事件触发的触发器会以您的身份运行脚本,并将新人员的电子邮件地址添加到群组中。
您也可以选择开启通知,以便在每次有人提交表单时收到电子邮件。

运作方式
当有人提交表单,其中包含用户的电子邮件地址以及应将该用户添加到的群组时,脚本会检查该用户是否已属于相应群组。如果用户已加入群组,则会收到一封电子邮件,确认他们已加入群组。否则,脚本会将用户添加到群组中,并向其发送欢迎电子邮件。
Apps 脚本服务
此解决方案使用以下服务:
- 脚本服务 - 创建每次有人提交表单时都会触发脚本的触发器。
- Google 群组服务 - 检查表单中提交的电子邮件地址是否已是相应群组的成员。
- Admin SDK 目录高级服务 - 将表单中提交的电子邮件地址添加到群组。
- 邮件服务 - 向表单中提交的电子邮件地址发送电子邮件,以确认其群组成员身份或欢迎其加入群组。
- 电子表格服务 - 将用户的状态添加到表单回答电子表格中。状态为已在群组中或新添加。
- 网址提取服务 - 将 Google 文档提取为 HTML 字符串。该文档包含脚本发送的电子邮件的内容。
前提条件
设置脚本
点击以下按钮可复制与新员工分享资源电子表格。此解决方案的 Apps 脚本项目已附加到电子表格中。
制作副本
依次点击扩展程序 > Google Apps 脚本。
在服务下,确保列出了 AdminDirectory 服务。如果已解决,请跳至第 6 步。如果不是,请继续执行下一步。
点击服务旁边的“添加服务”图标 add。
在对话框中,选择 Admin SDK API,然后点击添加。
在函数下拉菜单中,选择 installTrigger。
点击运行。
根据提示为脚本授权。
如果 OAuth 权限请求页面显示警告此应用未经过验证,请继续操作,依次选择高级 >
前往“{项目名称}”(不安全)。
重要提示:如果您多次运行此函数,系统会生成多个触发器,并发送重复的电子邮件。如需删除多余的触发器,请执行以下步骤:
- 点击触发器
。
- 依次点击触发器旁边的“更多”图标
> 删除触发器。
运行脚本
- 返回到电子表格,然后依次点击工具
> 管理表单
> 前往实时表单。
- 在表单中填写您的电子邮件地址以及您有权管理成员资格的群组,然后点击提交。
- 返回电子表格并查看表单条目。“状态”列会显示您的电子邮件地址是否已添加到相应群组或是否已是相应群组的成员。
- 查看您的电子邮件,看看是否收到了欢迎电子邮件或群组成员资格确认电子邮件。
贡献者
此示例由 Google 在 Google 开发者专家的帮助下维护。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):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)"]]