A library is a script project whose functions can be reused in other scripts. To include a library in your project you must have at least view-level access to it. If you aren't the author of the library that you want to include, contact the author and request access. You need the script ID of the library you want to include. When you have access to the library, you can find the script ID on the Project Settings page. Use your included library as you would use a default service. For example, if The reference
documentation for an included library can be opened by following these steps: At the left of the script editor, next to the library name, click More > Open in a new tab. Remove a libraryAt the left of the script editor, next to the library name, click More > Remove > Remove library. Update a libraryYou can change the version of the library or update its identifier.
To use and share your script project as a library, follow the below steps.
Best practicesHere are some guidelines to follow when writing a library:
Resource scopingThere are two types of resources when you are working with libraries: shared and not-shared. A shared resource means that both the library and the including script have a built-in access to the same instance of the resource. The following diagram illustrates a shared resource using the example of User Properties: A not-shared resource means that both library and the including script have built-in access only to their instance of the resource. However, a library can provide access to its not-shared resources by having explicit functions that operate on them. Here is an example of a function that you would include in your library to expose its Script Properties:
The following diagram illustrates a not-shared resource using the example of Script Properties: This table lists the shared and not-shared resources for your reference:
Test a libraryTo test your library, use the head deployment. Anyone who has editor-level access to the script can use the head deployment. Debug a libraryWhen you use the debugger in a project that includes a library you can step into a function of the included library. The code shows up in the debugger in view-only mode and at the right version. Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Last updated 2022-09-27 UTC. [{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }] [{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }] |