منابع را با افراد جدید به اشتراک بگذارید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
سطح کدنویسی : مبتدی
مدت زمان : 20 دقیقه
نوع پروژه : اتوماسیون با یک ماشه رویداد محور
اهداف
- درک کنید که راه حل چه کاری انجام می دهد.
- آنچه را که سرویس های Apps Script در راه حل انجام می دهند، بدانید.
- اسکریپت را تنظیم کنید
- اسکریپت را اجرا کنید.
در مورد این راه حل
مهم : برای استفاده از این راه حل، باید مدیر Google Workspace باشید.
منابع را با کارکنان ورودی در یک مرحله به اشتراک بگذارید. این راه حل از فرمی در Google Forms برای اضافه کردن کارمندان جدید به گروهی در Google Groups استفاده می کند. با به اشتراک گذاری منابع با آدرس آن گروه، می توانید به راحتی به استخدام کنندگان جدید اجازه دسترسی به منابع مورد نیاز خود را بدهید.
اگر مجوز اضافه کردن کاربران به یک گروه را دارید، می توانید از این راه حل برای تقسیم مسئولیت بین سایر اعضای تیم خود استفاده کنید. هنگامی که آنها فرم را ارسال می کنند، ماشه رویداد محور اسکریپت را به عنوان شما اجرا می کند و ایمیل شخص جدید را به گروه اضافه می کند.
به صورت اختیاری، میتوانید اعلانها را روشن کنید تا هر بار که شخصی فرم را ارسال میکند، ایمیلی دریافت کنید .


چگونه کار می کند
وقتی شخصی فرمی را با ایمیل کاربر ارسال می کند و گروهی که کاربر باید به آن اضافه شود، اسکریپت بررسی می کند که آیا شخص قبلاً به آن گروه تعلق دارد یا خیر. اگر این کار را انجام دهد، کاربر ایمیلی دریافت می کند که تأیید می کند قبلاً در گروه حضور دارند. در غیر این صورت، اسکریپت کاربر را به گروه اضافه کرده و یک ایمیل خوشامدگویی برای آنها ارسال می کند.
خدمات اسکریپت برنامه ها
این راه حل از خدمات زیر استفاده می کند:
- سرویس اسکریپت – ماشه ای را ایجاد می کند که هر بار که شخصی فرمی را ارسال می کند، اسکریپت را فعال می کند.
- سرویس گروه ها - بررسی می کند که آیا ایمیل ارسال شده در فرم قبلاً عضو گروه است یا خیر.
- سرویس پیشرفته Admin SDK Directory - ایمیل ارسال شده در فرم را به گروه اضافه می کند.
- سرویس پست الکترونیکی - یک ایمیل به آدرس ایمیل ارسال شده در فرم ارسال می کند تا عضویت آنها در گروه را تأیید کند یا به آنها خوشامد بگوید.
- سرویس صفحه گسترده - وضعیت کاربر را به صفحه گسترده پاسخ های فرم اضافه می کند. وضعیت یا قبلاً در گروه است یا به تازگی اضافه شده است .
- سرویس واکشی URL - یک سند Google Docs را به عنوان یک رشته HTML واکشی می کند. سند حاوی محتوای ایمیلی است که اسکریپت ارسال می کند.
پیش نیازها
اسکریپت را تنظیم کنید
روی دکمه زیر کلیک کنید تا صفحه گسترده اشتراکگذاری منابع با استخدامهای جدید را کپی کنید. پروژه Apps Script برای این راه حل به صفحه گسترده پیوست شده است.
یک کپی تهیه کنید
روی برنامههای افزودنی > اسکریپت برنامهها کلیک کنید.
در بخش Services ، مطمئن شوید که سرویس AdminDirectory فهرست شده است. اگر چنین است، به مرحله 6 بروید. اگر اینطور نیست، به مرحله بعدی ادامه دهید.
در کنار Services ، روی Add a service add کلیک کنید.
در گفتگو، Admin SDK API را انتخاب کنید و روی Add کلیک کنید.
در منوی تابع، installTrigger را انتخاب کنید.
روی Run کلیک کنید.
وقتی از شما خواسته شد، اسکریپت را مجاز کنید. اگر صفحه رضایت OAuth اخطار را نشان میدهد، این برنامه تأیید نشده است ، با انتخاب پیشرفته > رفتن به {Project Name} (ناامن) ادامه دهید.
مهم : اگر این عملکرد را بیش از یک بار اجرا کنید، چندین راهانداز ایجاد میکند و ایمیلهای تکراری ارسال میکند. برای حذف محرک های اضافی، مراحل زیر را انجام دهید:
- روی Triggers کلیک کنید
. - در کنار ماشه، روی More کلیک کنید
> حذف ماشه .
اسکریپت را اجرا کنید
- به صفحه گسترده بازگردید و روی ابزارها > مدیریت فرم > رفتن به فرم زنده کلیک کنید.
- فرم را با آدرس ایمیل خود و گروهی که مجوز مدیریت عضویت را دارید پر کنید و روی ارسال کلیک کنید.
- به صفحه گسترده بازگردید و ورودی فرم را مشاهده کنید. ستون وضعیت نشان می دهد که آیا آدرس ایمیل شما به گروه اضافه شده است یا قبلاً عضوی از آن بوده اید.
- ایمیل خود را برای دریافت ایمیل خوش آمدگویی یا تایید عضویت در گروه بررسی کنید.
مشارکت کنندگان
این نمونه توسط گوگل با کمک کارشناسان توسعه دهنده گوگل نگهداری می شود.
مراحل بعدی
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\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)"]]