با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
Google Apps Script بیش از 30 سرویس داخلی را برای تعامل با داده های کاربر، سایر سیستم های Google و سیستم های خارجی ارائه می دهد. این خدمات به عنوان اشیاء جهانی مشابه شیء استاندارد Math جاوا اسکریپت ارائه می شوند. به عنوان مثال، همانطور که Math متدهایی مانند random() و ثابت هایی مانند PI را ارائه می دهد، سرویس Apps Script Spreadsheet روش هایی مانند openById(id) ، کلاس ها (اشیاء فرزند) مانند Range و enum هایی مانند DataValidationCriteria را ارائه می دهد.
اسناد مرجع خدماتی که محصولات Google Workspace را کنترل می کنند در بخش "خدمات Google Workspace" در زیر عنوان "مرجع" در نوار کناری این سایت جمع آوری شده است. خدمات ابزار (برای مواردی مانند ایجاد رابط کاربری، تجزیه XML یا نوشتن دادههای گزارش) در بخش «خدمات اسکریپت» جمعآوری میشوند.
ویژگی های جاوا اسکریپت مدرن
Apps Script از دو زمان اجرا جاوا اسکریپت پشتیبانی می کند: زمان اجرا V8 مدرن و یک نسخه قدیمی تر که توسط مفسر جاوا اسکریپت Rhino Mozilla طراحی شده است.
هر زمان اجرا از کلاسها و اشیاء جاوا اسکریپت پشتیبانی میکند که علاوه بر سرویسهای داخلی و پیشرفته Google برای اسکریپت شما در دسترس هستند. اسکریپتهای شما میتوانند از اشیاء معمولی مانند Array ، Date ، RegExpو غیره و همچنین شیهای سراسری Math و Object استفاده کنند.
با استفاده از تکمیل خودکار
ویرایشگر اسکریپت یک ویژگی «کمک محتوا» را ارائه میکند که معمولاً «تکمیل خودکار» نامیده میشود، که اشیاء سراسری و همچنین روشها و فهرستهایی را که در زمینه فعلی اسکریپت معتبر هستند را نشان میدهد. هر زمان که نقطه ای را بعد از یک شی سراسری، enum یا فراخوانی روشی که کلاس Apps Script را برمی گرداند، تایپ می کنید، پیشنهادات تکمیل خودکار به طور خودکار ظاهر می شوند. به عنوان مثال:
اگر نام کامل یک شی سراسری را تایپ کردید یا یکی را از تکمیل خودکار انتخاب کردید، سپس تایپ کنید . (یک نقطه)، تمام متدها و شماره های آن کلاس را خواهید دید.
اگر چند نویسه را تایپ کنید، همه پیشنهادات معتبری را که با آن نویسه ها شروع می شود، مشاهده خواهید کرد.
درک اشیاء جهانی
هر سرویس حداقل یک شیء جهانی (سطح بالا) را ارائه می دهد. به عنوان مثال، سرویس Gmail فقط از شی GmailApp قابل دسترسی است. برخی از خدمات چندین شیء جهانی را ارائه می دهند. به عنوان مثال، سرویس Base شامل چهار شیء سراسری است: Browser ، Logger ، MimeType و Session .
روش های فراخوانی
اشیاء جهانی تقریباً همه سرویسهای داخلی یا پیشرفته شامل روشهایی هستند که دادهها یا کلاس Apps Script را برمیگردانند. اسکریپت ها فراخوانی متد را در این قالب انجام می دهند:
GmailApp.sendEmail('claire@example.com','Subject line','This is the body.');
اگر متدی یک کلاس Apps Script دیگر را برمی گرداند، می توانید فراخوانی های متد را در یک خط زنجیره بزنید. (انواع بازگشتی هم در تکمیل خودکار و هم در مستندات مرجع یک متد نشان داده می شوند.) برای مثال، متد DocumentApp.create() یک Document برمی گرداند. بنابراین، دو بخش کد زیر معادل هستند:
هر سرویس شامل یک یا چند کلاس فرزند است که نمی توان از سطح بالا به عنوان یک شی سراسری به آنها دسترسی داشت. شما نمی توانید از کلمه کلیدی new برای ساخت این کلاس ها استفاده کنید، همانطور که می توانید با کلاس های استاندارد جاوا اسکریپت مانند Date ; شما فقط با فراخوانی متدی که آن را برمی گرداند می توانید به کلاس فرزند دسترسی پیدا کنید. اگر مطمئن نیستید که چگونه به کلاس خاصی دسترسی داشته باشید، از صفحه اصلی برای مستندات مرجع سرویس دیدن کنید و به دنبال روشی باشید که کلاس مورد نظر شما را برمی گرداند.
برخورد با رابط ها
تعداد انگشت شماری از خدمات شامل کلاس های ویژه ای است که در مستندات مرجع به عنوان "رابط" برچسب گذاری شده اند. اینها کلاس های عمومی هستند که به عنوان انواع برگشتی برای روش هایی استفاده می شوند که نمی توانند نوع دقیق را از قبل تعیین کنند. به عنوان مثال، روش سرویس سندBody.getChild(childIndex) یک شی Element عمومی را برمی گرداند. Element رابطی است که کلاس دیگری را نشان می دهد، احتمالاً یک Paragraph یا Table . اشیاء رابط به ندرت به تنهایی مفید هستند. در عوض، معمولاً می خواهید متدی مانند Element.asParagraph() فراخوانی کنید تا شی را به یک کلاس دقیق برگردانید.
کار با enums
بیشتر خدمات شامل چند عدد (انواع شمارش شده) از مقادیر نامگذاری شده است. به عنوان مثال، سرویس Drive از enums Access و Permission برای تعیین اینکه کدام کاربران به یک فایل یا پوشه دسترسی دارند، استفاده می کند. تقریباً در همه موارد، شما از شی سراسری به این فهرست ها دسترسی دارید. برای مثال، فراخوانی روش Folder.setSharing(accessType, permissionType) به این صورت است:
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eGoogle Apps Script offers 30+ built-in services for interacting with Google and external systems, accessible as global objects similar to JavaScript's \u003ccode\u003eMath\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eApps Script supports modern ECMAScript syntax and features with the V8 runtime, which is recommended over the older Rhino runtime.\u003c/p\u003e\n"],["\u003cp\u003eServices provide global objects like \u003ccode\u003eGmailApp\u003c/code\u003e or \u003ccode\u003eSpreadsheetApp\u003c/code\u003e to access methods for interacting with specific Google products.\u003c/p\u003e\n"],["\u003cp\u003eChild classes like \u003ccode\u003eRange\u003c/code\u003e or \u003ccode\u003eDocument\u003c/code\u003e are accessed by calling methods of their parent global objects, enabling chained method calls for efficiency.\u003c/p\u003e\n"],["\u003cp\u003eEnums, such as \u003ccode\u003eDriveApp.Access\u003c/code\u003e, provide named values for specific functionalities within services like Drive.\u003c/p\u003e\n"]]],[],null,["# Built-in Google Services\n\nGoogle Apps Script provides more than 30 built-in services for interacting with\nuser data, other Google systems, and external systems. These services are\nprovided as global objects akin to JavaScript's standard\n[`Math`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math)\nobject. For example, just as `Math` offers methods like `random()` and\nconstants like `PI`, Apps Script's\n[Spreadsheet service](/apps-script/reference/spreadsheet) offers methods like\n[`openById(id)`](/apps-script/reference/spreadsheet/spreadsheet-app#openById(String)),\nclasses (child objects) like\n[`Range`](/apps-script/reference/spreadsheet/range), and enums like\n[`DataValidationCriteria`](/apps-script/reference/spreadsheet/data-validation-criteria).\n\nThe reference documentation for services that control\nGoogle Workspace products are collected in the\n\"Google Workspace Services\" section under the\n\"Reference\" header in the sidebar of this site. Utility services (for things\nlike creating user interfaces, parsing XML, or writing log data) are collected\nin the \"Script Services\" section.\n\nModern JavaScript features\n--------------------------\n\nApps Script supports two JavaScript runtimes: the modern\n[**V8**](https://v8.dev/) runtime and an older one powered by Mozilla's\n[**Rhino JavaScript interpreter**](https://en.wikipedia.org/wiki/Rhino_(JavaScript_engine)).\n\nThe [V8 runtime](/apps-script/guides/v8-runtime) supports modern\n[ECMAScript](https://en.wikipedia.org/wiki/ECMAScript) syntax and features.\nThe Rhino runtime is based on the older\n[JavaScript 1.6](https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/1.6)\nstandard, plus a few features from\n[1.7](https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/1.7) and\n[1.8](https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/1.8).\nYou can [freely choose which runtime](/apps-script/guides/v8-runtime#enabling_the_v8_runtime)\nto use with your script, but the V8 runtime is strongly recommended.\n\nEach runtime supports JavaScript classes and objects that are available to your\nscript in addition to the built-in\nand [advanced Google services](/apps-script/guides/services/advanced). Your\nscripts can use common objects like\n[`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array),\n[`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date),\n[`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp),\n[and so forth](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference),\nas well as the\n[`Math`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math) and\n[`Object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)\nglobal objects.\n| **Note:** Because Apps Script code runs on Google's servers (with the exception of [HTML-service](/apps-script/guides/html) pages), browser-based JavaScript features like DOM manipulation or the [`Window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) API are not available in Apps Script.\n\nUsing autocomplete\n------------------\n\nThe script editor provides a \"content assist\" feature, more commonly called\n\"autocomplete,\" which reveals the global objects as well as methods and enums\nthat are valid in the script's current context. Autocomplete suggestions appear\nautomatically whenever you type a period after a global object, enum, or method\ncall that returns an Apps Script class. For example:\n\n- If you type the full name of a global object or select one from autocomplete, then type `.` (a period), you will see all methods and enums for that class.\n- If you type a few characters, you'll see all valid suggestions that begin with those characters.\n\nUnderstanding global objects\n----------------------------\n\nEach service provides at least one global (top-level) object; for example,\nthe [Gmail service](/apps-script/reference/gmail) is accessed solely from\nthe [`GmailApp`](/apps-script/reference/gmail/gmail-app) object. Some services\nprovide multiple global objects; for example, the\n[Base service](/apps-script/reference/base) includes four global objects:\n[`Browser`](/apps-script/reference/base/browser),\n[`Logger`](/apps-script/reference/base/logger),\n[`MimeType`](/apps-script/reference/base/mime-type), and\n[`Session`](/apps-script/reference/base/session).\n\nCalling methods\n---------------\n\nThe global objects of nearly all built-in or\n[advanced services](/apps-script/guides/services/advanced) include methods that\nreturn data or an Apps Script class. Scripts make method calls in this format: \n\n GlobalObjectName.methodName(argument1, argument2, ..., argumentN);\n\nFor example, a script can send an email by calling the\n[`sendEmail(recipient, subject, body)`](/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String))\nmethod of the Gmail service like so: \n\n GmailApp.sendEmail('claire@example.com', 'Subject line', 'This is the body.');\n\nIf a method returns another Apps Script class, you can chain method calls on one\nline. (Return types are shown both in autocomplete and in a method's reference\ndocumentation.) For example, the method\n[`DocumentApp.create()`](/apps-script/reference/document/document-app#create(String))\nreturns a [`Document`](/apps-script/reference/document/document); thus, the\nfollowing two sections of code are equivalent: \n\n var doc = DocumentApp.create('New document');\n var body = doc.getTab('t.0').asDocumentTab().getBody();\n body.appendParagraph('New paragraph.');\n\n // Same result as above.\n DocumentApp.create('New document').getTab('t.0').asDocumentTab().getBody()\n .appendParagraph('New paragraph.');\n\nAccessing child classes\n-----------------------\n\nEvery service includes one or more child classes that cannot be accessed from\nthe top level as a global object can. You cannot use the `new` keyword to\nconstruct these classes, as you can with standard JavaScript classes like\n[`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date);\nyou can only access a child class by calling a method that returns it. If you're\nnot sure how to access a certain class, visit the root page for the service's\nreference documentation and look for a method that returns the class you want.\n\nDealing with interfaces\n-----------------------\n\nA handful of services include special classes that are labeled as \"interfaces\"\nin the reference documentation. These are generic classes used as return types\nfor methods that cannot determine the precise type in advance; for example,\nthe [Document service](/apps-script/reference/document) method\n[`Body.getChild(childIndex)`](/apps-script/reference/document/body#getChild(Integer))\nreturns a generic [`Element`](/apps-script/reference/document/element) object.\n`Element` is an interface that represents some other class, possibly a\n[`Paragraph`](/apps-script/reference/document/paragraph) or\n[`Table`](/apps-script/reference/document/table). Interface objects are rarely\nuseful on their own; instead, you usually want to call a method like\n[`Element.asParagraph()`](/apps-script/reference/document/element#asParagraph())\nto cast the object back to a precise class.\n\nWorking with enums\n------------------\n\nMost services include a few enums (enumerated types) of named values. For\nexample, the [Drive service](/apps-script/reference/drive) uses the enums\n[`Access`](/apps-script/reference/drive/access) and\n[`Permission`](/apps-script/reference/drive/permission) to determine which users\nhave access to a file or folder. In almost all cases, you access these enums\nfrom the global object. For example, a call to the method\n[`Folder.setSharing(accessType, permissionType)`](/apps-script/reference/drive/folder#setSharing(Access,Permission))\nlooks like this: \n\n // Creates a folder that anyone on the Internet can read from and write to. (Domain administrators can\n // prohibit this setting for Google Workspace users.)\n var folder = DriveApp.createFolder('Shared Folder');\n folder.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.EDIT);"]]