To understand how to use Global fields, let us try and create the “Address” Global field such that it can be used to enter address details of multiple employees within an organization.
Consider that the “Address” Global field consists of the following fields:
- House No
- Apartment Name
- Street Name
- Postal Code
All the entries in the “Address” Global field will share the same attributes, however, they will have different content.
To create a Global Field, log in to your Contentstack account, and perform the following steps:
- Go to the stack where you want to hold your Global Field, click on the CONTENT tab (if it is not open), and click on Global Fields at the top.
- Click on +New Global Field, this will direct you to the Create New Global Field form as shown below::
- Name the Global field Address and provide a suitable Description.
Tip: Refer to the Restricted keywords for UIDs section to understand which keywords cannot be used as UIDs for Global fields.
- Click on Create and Add fields.
Now that you have created the Global field, let us add fields and modify its properties as per your requirements.
The Global Field Builder page does not contain any fields by default. We will add fields such as “House Number,” “Apartment Name,” “Street Name,” “City,” and “Postal Code.”
To add custom fields to your Global field, drag and drop the fields from the Fields list at the left-hand side.
Let us go through the steps to add each of these fields.
- For the House No field, use the Single Line Textbox field.
- Drag and drop the Single Line Textbox field for Apartment Name.
- Use the Single Line Textbox field for Street Name.
- Drag and drop the Single Line Textbox field for City.
- Finally, we will use the Number field for Postal Code.
- Click on either Save or Save and Close.
Modify the behavior of your added fields by clicking on the respective fields and editing their properties.
Your finished “Address” Global field should be something similar to the following screenshot:
Tip: To modify these properties of the fields, click on a field bar and then edit its properties in the form that opens up on the right-hand side.
To perform the Create action via API, refer to the Create a Global Field API request