Zadbaj o dobrą organizację dzięki kolekcji Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Pobieranie odpowiedzi schema
Builder, aby utworzyć odpowiedź getSchema() dla projektu skryptu.
functiongetSchema(){constcc=DataStudioApp.createCommunityConnector();constfields=cc.getFields();fields.newDimension().setId('Created').setName('Date Created').setDescription('The date that this was created').setType(cc.FieldType.YEAR_MONTH_DAY);fields.newMetric().setId('Amount').setName('Amount (USD)').setDescription('The cost in US dollars').setType(cc.FieldType.CURRENCY_USD);returncc.newGetSchemaResponse().setFields(fields).build();}
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-07-26 UTC."],[[["\u003cp\u003e\u003ccode\u003egetSchemaResponse\u003c/code\u003e facilitates the creation of a schema for your Data Studio Community Connector, defining the structure of data your connector provides.\u003c/p\u003e\n"],["\u003cp\u003eIt allows you to specify dimensions and metrics, including their data types, descriptions, and IDs, using the \u003ccode\u003efields\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ebuild()\u003c/code\u003e method finalizes the schema definition and returns a validated object in the format required by Data Studio.\u003c/p\u003e\n"],["\u003cp\u003eAdditional methods like \u003ccode\u003eprintJson()\u003c/code\u003e and \u003ccode\u003esetFields()\u003c/code\u003e are available for debugging and further schema customization.\u003c/p\u003e\n"]]],["The `getSchema()` function defines data fields for a script project using the `DataStudioApp` service. It creates a dimension field named \"Date Created\" of `YEAR_MONTH_DAY` type and a metric field \"Amount (USD)\" of `CURRENCY_USD` type. The `newGetSchemaResponse()` builder then compiles and validates these fields using `setFields()` before the final format for Data Studio is produced using `build()`. `printJson()` outputs a JSON representation for debugging.\n"],null,["GetSchemaResponse\n\nBuilder to create a `get``Schema()` response for your script project.\n\n```javascript\nfunction getSchema() {\n const cc = DataStudioApp.createCommunityConnector();\n const fields = cc.getFields();\n\n fields.newDimension()\n .setId('Created')\n .setName('Date Created')\n .setDescription('The date that this was created')\n .setType(cc.FieldType.YEAR_MONTH_DAY);\n\n fields.newMetric()\n .setId('Amount')\n .setName('Amount (USD)')\n .setDescription('The cost in US dollars')\n .setType(cc.FieldType.CURRENCY_USD);\n\n return cc.newGetSchemaResponse().setFields(fields).build();\n}\n``` \n\nMethods\n\n| Method | Return type | Brief description |\n|-----------------------------------------|------------------------|------------------------------------------------------------------------------|\n| [build()](#build()) | `Object` | Validates this object and returns it in the format needed by Data Studio. |\n| [printJson()](#printJson()) | `String` | Prints the JSON representation of this object. |\n| [setFields(fields)](#setFields(Fields)) | [GetSchemaResponse](#) | Sets the [Fields](/apps-script/reference/data-studio/fields) of the builder. |\n\nDetailed documentation \n\n`build()` \nValidates this object and returns it in the format needed by Data Studio.\n\nReturn\n\n\n`Object` --- The validated [GetSchemaResponse](#) object.\n\n*** ** * ** ***\n\n`print``Json()` \nPrints the JSON representation of this object. This is for debugging only.\n\nReturn\n\n\n`String`\n\n*** ** * ** ***\n\n`set``Fields(fields)` \nSets the [Fields](/apps-script/reference/data-studio/fields) of the builder.\n\nParameters\n\n| Name | Type | Description |\n|----------|-----------------------------------------------------|--------------------|\n| `fields` | [Fields](/apps-script/reference/data-studio/fields) | The fields to set. |\n\nReturn\n\n\n[GetSchemaResponse](#) --- This builder, for chaining."]]