Field Types

Examples for managing complex field types such as MultilistField and NameValueListField.

Edit MultilistField

Example: The following demonstrates how to set a field to a known list of Ids. The Id is already converted to a GUID string.

# Hardcoded list of Ids.
$item.Editing.BeginEdit()
$item["Allowed Controls"] = "{guid1}|{guid2}|{guid3}"
$item.Editing.EndEdit()
# Array of Ids.
$array = [System.Collections.ArrayList]@()
$array.Add({guid1}) > $null
$array.Add({guid2}) > $null
$ids = [System.String]::Join("|", $array)
$item.Editing.BeginEdit()
$item["Allowed Controls"] = $ids
$item.Editing.EndEdit()

Example: The following replaces an instance of an Id with an alternate Id. The Id is already converted to a GUID string.

[Sitecore.Data.Fields.MultilistField]$field = $item.Fields["Allowed Controls"]
$item.Editing.BeginEdit()
$field.Replace("{493B3A83-0FA7-4484-8FC9-4680991CF742}","{493B3A83-0FA7-4484-8FC9-4680991CF743}")
$item.Editing.EndEdit()

Example: The following adds new Ids to an existing list. Makes use of the Sitecore.Text.ListString class.

Example: The following appends an ID to a set of items in all languages. It verifies that the field Keywords exists.

Example: The following example gets all of the items of a MultilistField and append a specific ID, ensuring that it's delimited with the | character.

Example: The following example extracts the items from a 'keywords' field, comma separates the values, and then outputs to a report.

Edit NameValueListField

Example: The following example gets all of the name/value pairs of a NameValueListField and appends a new pair.

Last updated