GlobalFieldRefs

View as Markdown

GlobalFieldRefs

GlobalFieldRefs records one nested global field inside the schema of a global field. It holds the UID of the nested global field, the number of times the schema uses it, and the schema paths where it occurs. A list of them sits in ContentModelling.GlobalFieldRefs.

When to Use This Class: Use this class when you create or read a GlobalField that contains another global field.

Conceptual Role: Acts as the data model that the SDK serializes into the global_field_refs array of a global field.

Returns: GlobalFieldRefs. One nested global field reference.

Properties

NameTypeRequiredDefaultDescription
Uidstring?NonullUID of the nested global field. Serialized as uid.
OccurrenceCountintNo0Number of times the schema uses the nested global field. Serialized as occurrence_count.
IsChildboolNofalsetrue when the nested global field is a child reference. Serialized as isChild.
PathsList<string>?NonullSchema paths where the nested global field occurs, for example schema.1. Serialized as paths.

Class-Level Notes

How it relates to the schema.

  • The nested global field itself is a GlobalFieldReference entry in ContentModelling.Schema. GlobalFieldRefs only describes where that entry sits.
  • The SDK does not fill this list for you, and it does not check that it matches the schema.

Values the SDK always sends.

  • OccurrenceCount and IsChild are value types, so the SDK sends occurrence_count and isChild with 0 and false when you do not set them. The SDK leaves out uid and paths when they are null.

Method Index

GlobalFieldRefs has no methods. Add instances to ContentModelling.GlobalFieldRefs, then pass the model to the Create method of GlobalField.

Class-Level Snippet

The snippet below creates a Page Header global field that nests the seo global field, and records the nesting in GlobalFieldRefs.

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.Fields;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

ContentModelling model = new ContentModelling
{
    Title = "Page Header",
    Uid = "page_header",
    Schema = new List<Field>
    {
        new TextboxField { DisplayName = "Heading", Uid = "heading", DataType = "text" },
        new GlobalFieldReference { DisplayName = "SEO", Uid = "seo", DataType = "global_field", ReferenceTo = "seo" }
    },
    GlobalFieldRefs = new List<GlobalFieldRefs>
    {
        new GlobalFieldRefs { Uid = "seo", OccurrenceCount = 1, IsChild = true, Paths = new List<string> { "schema.1" } }
    }
};

try
{
    ContentstackResponse response = client
        .Stack("<API_KEY>")
        .GlobalField(apiVersion: "<API_VERSION>")
        .Create(model);
    Console.WriteLine(response.OpenJsonObjectResponse()["global_field"]?["uid"]);
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}