تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
توفّر خدمة "برمجة تطبيقات Google" أكثر من 30 خدمة مدمجة للتفاعل مع بيانات المستخدمين وأنظمة Google الأخرى والأنظمة الخارجية. يتم توفير هذه الخدمات كعناصر عامة مشابهة لعنصر Math العادي في JavaScript. على سبيل المثال، كما يوفّر Math طرقًا مثل random() وثوابت مثل PI، يوفّر خدمة جداول بيانات في Apps Script طرقًا مثل openById(id) وفئات (عناصر فرعية) مثل Range وقيم تعدادية مثل DataValidationCriteria.
يتم جمع المستندات المرجعية للخدمات التي تتحكّم في منتجات Google Workspace في قسم "خدمات Google Workspace" ضمن العنوان "مرجع" في الشريط الجانبي لهذا الموقع الإلكتروني. يتم جمع خدمات الأدوات المساعدة (مثل إنشاء واجهات المستخدم أو تحليل XML أو كتابة بيانات السجلّ) في قسم "خدمات البرامج النصية".
ميزات JavaScript الحديثة
تتوافق Apps Script مع وقتَي تشغيل JavaScript، وهما وقت التشغيل الحديث V8 ووقت التشغيل القديم الذي يعتمد على مفسّر Rhino JavaScript من Mozilla.
يتيح كل وقت تشغيل فئات JavaScript وعناصرها المتاحة للبرنامج النصي بالإضافة إلى خدمات Google المتقدّمة المضمّنة. يمكن أن تستخدم النصوص البرمجية كائنات شائعة، مثل Array وDate وRegExp ووما إلى ذلك، بالإضافة إلى الكائنَين العامَين Math وObject.
استخدام ميزة "الإكمال التلقائي"
يوفّر محرِّر النصوص البرمجية ميزة "مساعدة في المحتوى"، والتي تُعرف باسم "الإكمال التلقائي"، وتكشف عن العناصر العامة بالإضافة إلى الطرق والتعدادات الصالحة في السياق الحالي للنص البرمجي. تظهر اقتراحات الإكمال التلقائي تلقائيًا عند كتابة نقطة بعد كائن عام أو تعداد أو استدعاء طريقة تعرض فئة Apps Script. على سبيل المثال:
إذا كتبت الاسم الكامل لعنصر عام أو اخترت عنصرًا من الإكمال التلقائي،
ثم كتبت . (نقطة)، ستظهر لك جميع الطرق والقيم الثابتة لتلك الفئة.
إذا كتبت بضعة أحرف، ستظهر لك كل الاقتراحات الصالحة التي تبدأ بهذه الأحرف.
فهم العناصر العامة
تقدّم كل خدمة عنصرًا واحدًا على الأقل على مستوى العالم (المستوى الأعلى)، على سبيل المثال، لا يمكن الوصول إلى خدمة Gmail إلا من خلال العنصر GmailApp. تقدّم بعض الخدمات عدة عناصر عامة، مثلاً، تتضمّن الخدمة الأساسية أربعة عناصر عامة هي: Browser وLogger وMimeType وSession.
طُرق الاتصال
تتضمّن الكائنات العامة لجميع الخدمات المتقدّمة أو المضمّنة تقريبًا طرقًا تعرض بيانات أو فئة من فئات Apps Script. تجري النصوص البرمجية عمليات استدعاء الطرق بهذا التنسيق:
على سبيل المثال، يمكن لنص برمجي إرسال رسالة إلكترونية من خلال استدعاء طريقة
sendEmail(recipient, subject, body)
الخاصة بخدمة Gmail على النحو التالي:
GmailApp.sendEmail('claire@example.com','Subject line','This is the body.');
إذا عرضت إحدى الطرق فئة أخرى من فئات "برمجة التطبيقات"، يمكنك ربط استدعاءات الطرق في سطر واحد. (يتم عرض أنواع الإرجاع في كلّ من الإكمال التلقائي وفي مستندات مرجع الطريقة). على سبيل المثال، تعرض الطريقة
DocumentApp.create()
القيمة Document، وبالتالي، فإنّ القسمَين التاليَين من الرمز البرمجي متكافئان:
تتضمّن كل خدمة فئة فرعية واحدة أو أكثر لا يمكن الوصول إليها من المستوى الأعلى كما يمكن الوصول إلى عنصر عام. لا يمكنك استخدام الكلمة الأساسية new لإنشاء هذه الفئات، كما يمكنك مع فئات JavaScript العادية مثل Date؛ يمكنك فقط الوصول إلى فئة فرعية من خلال استدعاء طريقة تعرضها. إذا لم تكن متأكدًا من كيفية الوصول إلى فئة معيّنة، انتقِل إلى صفحة الجذر الخاصة بالمستندات المرجعية للخدمة وابحث عن طريقة تعرض الفئة التي تريدها.
التعامل مع الواجهات
تتضمّن بعض الخدمات فئات خاصة مصنّفة على أنّها "واجهات" في المستندات المرجعية. هذه فئات عامة تُستخدَم كأنواع إرجاع للطُرق التي لا يمكنها تحديد النوع الدقيق مسبقًا، على سبيل المثال، تعرض طريقة خدمة المستنداتBody.getChild(childIndex) عنصر Element عام.
Element هي واجهة تمثّل فئة أخرى، ربما تكون Paragraph أو Table. ونادرًا ما تكون عناصر الواجهة مفيدة بمفردها، بل تحتاج عادةً إلى استدعاء طريقة مثل
Element.asParagraph()
لتحويل العنصر مرة أخرى إلى فئة دقيقة.
العمل باستخدام التعدادات
تتضمّن معظم الخدمات بعض القيم الثابتة (أنواع تعدادية) للقيم المسماة. على سبيل المثال، تستخدم خدمة Drive القيمتين التعداديتين Access وPermission لتحديد المستخدمين الذين يمكنهم الوصول إلى ملف أو مجلد. في جميع الحالات تقريبًا، يمكنك الوصول إلى هذه القيم
المحدّدة مسبقًا من العنصر العام. على سبيل المثال، تبدو الدعوة إلى الطريقة
Folder.setSharing(accessType, permissionType)
على النحو التالي:
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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);"]]