Class GetSchemaResponse
Stay organized with collections
Save and categorize content based on your preferences.
GetSchemaResponse
Builder to create a getSchema()
response for your script project.
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();
}
Detailed documentation
build()
Validates this object and returns it in the format needed by Data Studio.
Return
Object
— The validated GetSchemaResponse
object.
printJson()
Prints the JSON representation of this object. This is for debugging only.
Return
String
setFields(fields)
Sets the Fields
of the builder.
Parameters
Name | Type | Description |
fields | Fields | The fields to set. |
Return
GetSchemaResponse
— This builder, for chaining.
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 2024-12-02 UTC.
[null,null,["Last updated 2024-12-02 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,["# 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."]]