ContentTypes

Configure SharePoint content types in a web or list.


Access

Access the ContentTypes API using the contentTypes property of Web or List.

Examples

up(engineer) {
// Add content type to web
engineer.web.contentTypes.add('My Content Type');

// Add content type to list
engineer.web.lists.getByTitle('My List').contentTypes.add('My Content Type');
}

Methods

getById(id)

Get a content type by its ID or GUID. We highly recommend using the getByName method for any custom content types created by Engineer, as the content type ID may change from environment to environment.

Parameters

id
The ID or GUID of the content type to be retrieved (String, required)

Returns

ContentType

Examples

up(engineer) {
// Add field to content type
engineer.web.contentTypes.getById('0x0100CF4BED4219E64B26A321633450759400').fieldLinks.add('My Field');
}

getByName(name)

Get a content type by its name. This method can only be used with content types that were previously created in an active migration. Engineer uses a content type ID manifest list, which is updated automatically any time a content type is created or deleted within a migration. The manifest is used to keep track of all content type IDs for each environment, even if they differ between any two environments.

Parameters

name
The name or title of the content type to be retrieved (String, required)

Returns

ContentType

Examples

down(engineer) {
// Delete content type
engineer.web.contentTypes.getByName('My Content Type').delete();
}

add(options|name)

Add a new content type to the target Web or List.

Parameters

options
New content type configuration (Object, required)
name
If a String is provided instead of options, a new content type of this name will be created with default configuration (String, override)

Properties of options

ParentContentType
The Name of the parent content type; note that this can only be used with content types previously created in an active migration; ParentContentTypeId will be automatically set when supplying this property (String, optional)
ParentContentTypeId
The ID or GUID of the parent content type (default: "0x01") (String, optional)
Id
The ID or GUID of the new content type, which will be automatically appended to the ParentContentTypeId during creation; if no ID is provided, a new GUID will be automatically generated; use the guid command to easily generate new IDs (String, optional)
Name
The name or title of the new content type (String, required)
Description
A description of the new content type (String, optional)
Group
The group name under which this content type will appear in content type galleries (String, optional)

Examples

up(engineer) {
// Create content type of parent "Item"
engineer.web.contentTypes.add('Custom Item');

// Create content type of parent "Custom Item"
engineer.web.contentTypes.add({
ParentContentType: 'Custom Item',
Id: '01',
Name: 'Child Custom Item',
});

// Create content type of parent "Link"
engineer.web.contentTypes.add({
ParentContentTypeId: '0x0105',
Name: 'Custom Link',
Description: 'My custom link type',
Group: 'My Group',
});

// Create content type with persistent GUID
engineer.web.contentTypes.add({
ParentContentTypeId: '0x01',
Id: '42927AD563074FA48B0124083ED4616E',
Name: 'My Content Type with GUID',
Description: 'The ID of this content type will persist across environments',
Group: 'My Group',
});
}

addAvailable(options|name)

Add an existing content type to the target List. This method is not available in the context of a Web.

Parameters

options
Existing content type configuration (Object, required)
name
If a String is provided instead of options, a content type of this name will be added to the List (String, override)

Properties of options

Id
The ID or GUID of the existing content type; required if Name is not specified (String, optional)
Name
The name or title of the existing content type; note that content types can only be referenced by their name if they have been created in a previous migration and exist in the content type ID manifest; required if Id is not specified (String, required)

Examples

up(engineer) {
// Create new content type
engineer.web.contentTypes.add('Custom Item');

// Add new content type to list
engineer.web.lists.getByTitle('My List').contentTypes.addAvailable('Custom Item');

// Add "Link" content type by ID
engineer.web.lists.getByTitle('My List').contentTypes.addAvailable({
Id: '0x0105',
});
}

order(contentTypes)

Alter the default content type and ordering of content types in the target List. This method is not available in the context of a Web. This method uses the SharePoint client-side object model (CSOM).

Parameters

contentTypes
An array of content type String names representing the new order of content types available on the list; note that the first content type in the array will become the default content type for the list (Array, required)

Examples

up(engineer) {
// Add content types to list
engineer.web.lists.getByTitle('Animals').contentTypes.addAvailable('Cat');
engineer.web.lists.getByTitle('Animals').contentTypes.addAvailable('Dog');

// Set new content type order
engineer.web.lists.getByTitle('Animals').contentTypes.order([
'Dog',
'Cat',
]);
}

default(contentType)

Set a single default content type on the target List. This is similar to the order method, but accepts only a single content type name. This method is not available in the context of a Web. This method uses the SharePoint client-side object model (CSOM).

Parameters

contentType
The content type name that will be the new default content type for this list (String, required)

Examples

up(engineer) {
// Add content type to list
engineer.web.lists.getByTitle('Animals').contentTypes.addAvailable('Dog');

// Set default content type
engineer.web.lists.getByTitle('Animals').contentTypes.default('Dog');
}