Skip to main content
Browse Documentation

Entry methods

Created by Richard Saunders, last modified by Scott Yearsley on 15 Nov 2019

Get

Gets a field from an entry by fieldName and returns a dynamic object instance.

Syntax

public dynamic Get(string fieldName, bool autoResolve = true)
{
}

Parameters

fieldName

Type: string
The name of the requested field

autoResolve

Type: string
If set to true for a singular/list of entries, assets or images, it will automatically request the linked resource when invoked. A value of false should be specified if you only require the link properties such as Uri or contentTypeId and do not want the performance overhead of retrieving the entire resource. The default is true.

Remarks

Returns null if the field is not found or if the field value is null.

Example

// Get the title field as dynamic
dynamic title = entry.Get("title")

Get <T>

Gets a field from an entry by fieldName and returns a typed object instance.

Syntax

public T Get<T>(string fieldName, bool autoResolve = true)
{
}

Parameters

T

The type to attempt to cast the field data to. The type will either be a DataType, a supported DataFormat type or a custom type.

fieldName

Type: string
The name of the requested field

autoResolve

Type: string
If set to true for a singular/list of entries, assets or images, it will automatically request the linked resource when invoked. A value of false should be specified if you only require the link properties such as Uri or contentTypeId and do not want the performance overhead of retrieving the entire resource. The default is true.git

Remarks

If the API cannot successfully cast or convert the field value then it will return the default for the specified type. Requesting field values by the wrong type will not result in exceptions being thrown.

Example

// Get the title field as defined type
string title = entry.Get<string>("title")

HasValue

Determines whether the field exists and the value is not null.

Syntax

public bool HasValue(string fieldName)
{
}

Parameters

fieldName

Type: string
The name of the field to check

Return value

Type: boolean
true if the field exists and is not null, otherwise false

Remarks

If the fieldName is not defined in the content type that the entry is based on then it will return null.

Example

if (entry.HasValue("title"))
{
    // Get the location field as type
    Location title = entry.Get<Location>("filmingLocation")
}