Class Fields

  • Fields define the dimensions and metrics available for use in Data Studio for a community connector.

  • You can retrieve fields as an array, build them for Data Studio format, or filter them by ID.

  • Methods exist to add new dimensions and metrics, and to set or get the default dimension and metric.

  • Individual fields within the set can be accessed by their ID.

Fields

Contains a set ofFields for a community connector. This set of fields define whichdimensions and metrics can be used in Data Studio.

constcc=DataStudioApp.createCommunityConnector();constfields=cc.getFields();constfield1=fields.newDimension()// Set other properties as needed..setId('field1_id');

Methods

MethodReturn typeBrief description
asArray()Field[]Returns a view of this object as an array.
build()Object[]Validates this object and returns it in the format needed by Data Studio.
forIds(ids)FieldsReturns a newFields object filtered toFields with an ID inids.
getDefaultDimension()FieldReturns the default dimension to be used for the set of fields.
getDefaultMetric()FieldReturns the default metric to be used for the set of fields.
getFieldById(fieldId)FieldReturns a field with a given ID, ornull if no field with that ID is in thisFields object.
newDimension()FieldReturns a new dimensionField.
newMetric()FieldReturns a new metricField.
setDefaultDimension(fieldId)voidSets the default dimension to be used for the set of fields.
setDefaultMetric(fieldId)voidSets the default metric to be used for the set of fields.

Detailed documentation

asArray()

Returns a view of this object as an array.

constfields=DataStudioApp.createCommunityConnector().getFields();fields.newDimension().setId('field1_id');fields.newDimension().setId('field2_id');fields.newDimension().setId('field3_id');// Logging the ID of each field:fields.asArray().map((field)=>{Logger.log(field.getId());});

Return

Field[] — An array ofField objects.


build()

Validates this object and returns it in the format needed by Data Studio.

Return

Object[] — The validated field data, represented as a list of objects.

Throws

Error — if a valid object cannot be constructed.


forIds(ids)

Returns a newFields object filtered toFields with an ID inids.

constfields=DataStudioApp.createCommunityConnector().getFields();fields.newDimension().setId('field1_id');fields.newDimension().setId('field2_id');fields.newDimension().setId('field3_id');// subsetFields is a Fields object that only contains field1 and field2.constsubsetFields=fields.forIds(['field1_id','field3_id']);

Parameters

NameTypeDescription
idsString[]The IDs of fields that should be kept.

Return

Fields — A newFields object.


getDefaultDimension()

Returns the default dimension to be used for the set of fields. The default dimension isselected automatically when a new visualization is made.

Return

Field — The dimension that is set as the default dimension, ornull if no default dimension was set.


getDefaultMetric()

Returns the default metric to be used for the set of fields. The default metric is selectedautomatically when a new visualization is made.

Return

Field — The metric that is set as the default metric, ornull if no default metric was set.


getFieldById(fieldId)

Returns a field with a given ID, ornull if no field with that ID is in thisFields object.

constfields=DataStudioApp.createCommunityConnector().getFields();constfield1=fields.newDimension().setId('field1_id');// byId is the same as field1.constbyId=fields.getFieldById('field1_id');// byId2 is null.constbyId2=fields.getFieldById('not present id');

Parameters

NameTypeDescription
fieldIdStringThe ID of the field to get.

Return

Field — TheField with the given ID, ornull if no such field is contained within thisFields object.


newDimension()

Returns a new dimensionField.

Return

Field — A new dimensionField.


newMetric()

Returns a new metricField.

Return

Field — A new metricField.


setDefaultDimension(fieldId)

Sets the default dimension to be used for the set of fields. The default dimension is selectedautomatically when a new visualization is made.

Parameters

NameTypeDescription
fieldIdStringThe ID of the field to use as the default dimension. This ID must be present in the set of fields.

setDefaultMetric(fieldId)

Sets the default metric to be used for the set of fields. The default metric is selectedautomatically when a new visualization is made.

Parameters

NameTypeDescription
fieldIdStringThe ID of the field to use as the default metric. This ID must be present in the set of fields.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.