Class GetSchemaResponse
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
取得結構定義回應建構工具,可為指令碼專案建立 getSchema()
回應。
function getSchema() {
const cc = DataStudioApp.createCommunityConnector();
const fields = 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);
return cc.newGetSchemaResponse().setFields(fields).build();
}
內容詳盡的說明文件
printJson()
列印此物件的 JSON 表示法。這項設定僅供偵錯。
回攻員
String
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\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,["# Class GetSchemaResponse\n\nGetSchemaResponse\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\n### Methods\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\n### `build()`\n\nValidates this object and returns it in the format needed by Data Studio.\n\n#### Return\n\n\n`Object` --- The validated [GetSchemaResponse](#) object.\n\n*** ** * ** ***\n\n### `print``Json()`\n\nPrints the JSON representation of this object. This is for debugging only.\n\n#### Return\n\n\n`String`\n\n*** ** * ** ***\n\n### `set``Fields(fields)`\n\nSets the [Fields](/apps-script/reference/data-studio/fields) of the builder.\n\n#### Parameters\n\n| Name | Type | Description |\n|----------|-----------------------------------------------------|--------------------|\n| `fields` | [Fields](/apps-script/reference/data-studio/fields) | The fields to set. |\n\n#### Return\n\n\n[GetSchemaResponse](#) --- This builder, for chaining."]]