[[["เข้าใจง่าย","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-04 UTC"],[[["\u003cp\u003eLibraries in Apps Script enable code reuse across different scripts but can impact execution speed, especially in UI-heavy applications or add-ons.\u003c/p\u003e\n"],["\u003cp\u003eTo use a library, you need its Script ID and at least view-level access, then add it to your project specifying the version and identifier.\u003c/p\u003e\n"],["\u003cp\u003eLibraries are accessed like built-in services; use the identifier followed by a period to view available methods.\u003c/p\u003e\n"],["\u003cp\u003eWhen creating a library, use meaningful names, consider visibility of methods (using underscores for private ones), and provide JSDoc documentation for user-facing functions.\u003c/p\u003e\n"],["\u003cp\u003eLibraries and scripts share certain resources like User Properties, while others, like Script Properties, are not shared and require explicit functions for access.\u003c/p\u003e\n"]]],[],null,["A library is a script project whose functions can be reused in other scripts.\n| **Warning:** A script that uses a library [doesn't run as quickly](/apps-script/guides/support/best-practices#avoid_libraries_in_ui-heavy_scripts) as it would if all the code were contained within a single script project. Although libraries can make development and maintenance more convenient, use them sparingly in projects where speed is critical. Because of this issue, library use should be limited in [add-ons](/workspace/add-ons/overview).\n\nGain access to a library\n\nTo include a library in your project you must have at least view-level\naccess to it. If you aren't the author of the library that you want to\ninclude, contact the author and request access.\n\nYou need the script ID of the library you want to include. When you have\naccess to the library, you can find the script ID on the **Project Settings**\nsettings page.\n\nAdd a library to your script project\n\n1. At the left of the Apps Script editor, next to \"Libraries,\" click Add a library add.\n2. In the \"Script ID\" field, paste in the script ID of the library.\n3. Click **Look up** . If you encounter an error, make sure that you have at least view-level access to the project that you're trying to include.\n4. Click the **Version** dropdown and select the version of the library to use.\n5. Check to see if the default \"Identifier\" name is the one that you want to use with this library. This is the name that your script uses to refer to the library. For example, if you set it to `Test` then you can call a method of that library as follows: `Test.libraryMethod()`. If you use an identifier name that matches the name of an already existing service, such as [`MailApp`](/apps-script/reference/mail/mail-app), or a previously added library, then the library you have added most recently overrides the existing service or library.\n6. Click **Add**.\n\nUse a library\n\nUse your included library as you would use a default service. For\nexample, if `Test` is the identifier for your library, type\n`Test` immediately followed by a period to see the list of methods in the library.\n\nThe reference documentation for an included library can be opened by following\nthese steps:\n\nAt the left of the script editor, next to the library name, click More\nmore_vert **\\\u003e Open in a new tab**.\n\nRemove a library\n\nAt the left of the script editor, next to the library name, click More\nmore_vert **\\\u003e Remove \\\u003e Remove library**.\n| If a library is deleted by the author you still need to remove it from your list of included libraries.\n\nUpdate a library\n\nYou can change the version of the library or update its identifier.\n\n1. At the left of the editor, under \"Libraries,\" click the name of the library.\n2. Make your changes and click **Save**.\n\nCreate and share a library\n\nTo use and share your script project as a library, follow the below steps.\n\n1. [Create a versioned deployment](/apps-script/guides/versions) of your script.\n2. Share at least view-level access with all potential users of the library.\n3. Give those users the script ID, which can be found on the **Project\n settings** settings page.\n\nBest practices\n\nHere are some guidelines to follow when writing a library:\n\n1. Choose a meaningful name for your project since it's used as the default identifier when your library is included by others.\n2. If you want one or more methods of your script to not be visible (nor usable) to your library users, you can end the name of the method with an underscore. For example, `myPrivateMethod_()`.\n3. Only enumerable global properties are visible to library users. This includes function declarations, variables created outside a function with `var`, and properties explicitly set on the global object. For example, `Object.defineProperty()` with `enumerable` set to `false` creates a symbol you can use in your library, but this symbol isn't accessible by your users.\n4. If you want your library users to make use of the script editor autocomplete and\n the automatically generated documentation, you must have JSDoc-style\n documentation for all your functions. Here's an example:\n\n /**\n * Raises a number to the given power, and returns the result.\n *\n * @param {number} base the number we're raising to a power\n * @param {number} exp the exponent we're raising the base to\n * @return {number} the result of the exponential calculation\n */\n function power(base, exp) { ... }\n\nResource scoping\n\nThere are two types of resources when you are working with libraries: shared\nand not-shared. A shared resource means that both the library and the including\nscript have a built-in access to the same instance of the resource. The\nfollowing diagram illustrates a shared resource using the example of\nUser Properties:\n\nA not-shared resource means that both library and the including script have\nbuilt-in access only to their instance of the resource. However, a library can\nprovide access to its not-shared resources by having explicit functions that\noperate on them. Here is an example of a function that you would include in\nyour library to expose its Script Properties: \n\n function getLibraryProperty(key) {\n const scriptProperties = PropertiesService.getScriptProperties();\n return scriptProperties.getProperty(key);\n }\n\nThe following diagram illustrates a not-shared resource using the example of\nScript Properties:\n\nThis table lists the shared and not-shared resources for your reference:\n\n| Resource | Shared\\* | Not-Shared\\*\\* | Notes |\n|------------------------------------|----------|----------------|------------------------------------------------------------------------------------|\n| Lock | | | The same instance is visible to all including scripts when created in the library. |\n| Script Properties | | | The same instance is visible to all including scripts when created in the library. |\n| Cache | | | The same instance is visible to all including scripts when created in the library. |\n| Triggers | | | Simple triggers created in library are not triggered by the including script. |\n| ScriptApp | | | |\n| UiApp | | | |\n| User Properties | | | |\n| Logger and execution transcript | | | |\n| Sites, Sheets and other containers | | | A call to `getActive()` returns the container of the including script. |\n| MailApp and GmailApp | | | |\n\nTest a library\n\nTo test your library, use the head deployment. Anyone who has editor-level\naccess to the script can use the head deployment.\n| You still need at least one version of the library saved.\n\nDebug a library\n\nWhen you use the debugger in a project that includes a library you\ncan step into a function of the included library. The code shows up in\nthe debugger in view-only mode and at the right version."]]