Custom Content Form Item Object

sdk.getItem() returns an Item object which holds item data.

Method Parameter Required Returns Usage
item.get()

None

n/a

Basic item properties.
{
    id: <id>,
    type: <type>,
    name: <name>,
    description: <description>,
    createdBy: <createdBy>,
    createdDate: <createdDate>,
    updatedBy: <updatedBy>,
    updatedDate: <updatedDate>,
    slug: <slug>,
    repositoryId: <repositoryId>,
    language: <language>,
    translatable: <translatable>,
    status: <status>,
    isPublished: <isPublished>,
    languageIsMaster: <languageIsMaster>,
    version: <version>,
    currentVersion: <currentVersion>,
    latestVersion: <latestVersion>,
    mimeType: <mimeType>,
    fileGroup: <fileGroup>,
    varSetId: <varSetId>
}
var itemProperties = item.get();
item.getLanguageOptions()

None

n/a

Method to return a list of language options applicable for creating new item. This method works for a new item only.

//when item is new build language dropdown
if(item.isNew()){
    var langOptions =   item.getLanguageOptions();
}
item.isNew()

None

n/a

Method to specify whether or not the item is new.
var isNewItem = item.isNew();
item.getFields() Object with height and width. n/a Method to return an array of Field objects.
var fields = item.getFields();
item.getFieldById(fieldId)

field ID

string

yes

Method to return a Field object by field ID.

var field = item.getFieldById(<fieldId>);
item.getFieldByName(fieldName)

field name

string

yes

Method to return a Field object by field name.

var field = item.getFieldByName(<fieldName>);
item.validateName(name)

name

string

yes

Validates a given name and returns a Promise. When fullfilled returns validation object.
// when valid
{
  isValid: true,
}
 
// when invalid
{
  isValid: false,
  errorMessageSummary: <error message>
  errorMessageDetail: <detail error message>
};
item.validateName(nameField.value).then(function (validation) {
  if (validation && validation.isValid) {
    // handle valid name
  } else {
    // display invalidation errors
  }
}).catch(function (error) {
  // handle error
});
item.validateDescription(description)

description

string

yes

Validates given description and returns a Promise. When fullfilled returns validation object.
// when valid
{
  isValid: true,
}
 
// when invalid
{
  isValid: false,
  errorMessageSummary: <error message>
  errorMessageDetail: <detail error message>
};
item.validateDescription(descField.value).then(function (validation) {
  if (validation && validation.isValid) {
    // handle valid description
  } else {
    //display invalidation errors
  }
}).catch(function (error) {
  // handle error
});
item.validateSlug(slug)

slug

string

yes

Validates given slug and returns a Promise. When fullfilled returns validation object.
// when valid
{
  isValid: true,
}
 
// when invalid
{
  isValid: false,
  errorMessageSummary: <error message>
  errorMessageDetail: <detail error message>
};
item.validateSlug(slugField.value).then(function (validation) {
  if (validation && validation.isValid) {
    // handle valid slug
  } else {
    // display invalidation errors
  }
}).catch(function (error) {
  // handle error
});
item.validateLanguage(language)

language

String

yes

Validates given language and returns a Promise. When fullfilled returns validation object.

// when valid
{
  isValid: true,
}
 
// when invalid
{
  isValid: false,
  errorMessageSummary: <error message>
  errorMessageDetail: <detail error message>
};
item.validateLanguage(language).then(function (validation) {
  if (validation && validation.isValid) {
    // handle valid
  } else {
    // display invalidation errors
  }
}).catch(function (error) {
  // handle error
});
item.setName(name,options)

name - string

options - object with {silent: true|false}

name - yes

options - optional

Sets item name. When options with silent:true property is passed, form doesn't become dirty.

// sets name and form becomes dirty
item.setName(name);

// sets name and form doesn't become dirty
item.setName(name, {silent: true});
item.setDescription(description,options)

description - string

options - object with {silent: true|false}

description - yes

options - optional

Sets item description. When options with silent: true property is passed, form doesn't become dirty.

item.setDescription(description);
item.setDescription(description, {silent: true});
item.setSlug(slug,options)

description - string

options - object with {silent: true|false}

slug - yes

options - optional

Sets slug value. When options with silent: true property is passed, form doesn't become dirty.

item.setSlug(slug);
item.setSlug(slug, {silent: true});
item.setLanguage(language,options)

languageCode - string

options - object with {silent: true|false}

language - yes

options - optional

Sets language. Works for new items only. When options with silent: true property is passed, form doesn't become dirty.

item.setLanguage('en-US');
item.setLanguage('en-US', {silent: true});
item.setTranslatable(isTranslatable,options)

isTranslatable - boolean

options - object with {silent: true|false}

setTranslatable - yes

options - optional

Sets whether or not the item is translatable. Will work only if the item is a new master. When options with silent: true property is passed, form doesn't become dirty.

item.setTranslatable(isTranslatable);
item.setTranslatable(isTranslatable, {silent: true});
item.on(event, handler)

event - string

handler - function that handles the event

yes

Currently only 'update' event is supported.

item.on('update', function(value){
   // called if the item values change in the UI
   // update item properties with latest value
   itemProps = value;
});
item.getChannels()

None

n/a

Returns a Promise. When fullfilled the channels of the item are returned.

item.getChannels().then(function (data) {
  console.log('Channels:', data);
});
item.getCollections()

None

n/a

Returns a Promise. When fullfilled the collections of the item are returned.

item.getCollections().then(function (data) {
  console.log('Collections :', data);
});
item.getTags()

None

n/a

Returns a Promise. When fullfilled the tags of the item are returned.

item.getTags().then(function (data) {
  console.log('Tags :', data);
});
item.getTaxonomies()

None

n/a

Returns a Promise. When fullfilled the taxonomies of the item are returned.

item.getTaxonomies().then(function (data) {
  console.log('Taxonomies :', data);
});
item.getVersionInfo()

None

n/a

Returns a Promise. When fullfilled the version information of the item is returned.

item.getVersionInfo().then(function (data) {
  console.log('Version info :', data);
});
item.getPublishInfo()

None

n/a

Returns a Promise. When fullfilled the publish information of the item is returned.

item.getPublishInfo().then(function (data) {
  console.log('Publish info :', data);
});
item.getPublishedChannels()

None

n/a

Returns a Promise. When fullfilled the published channels of the item are returned.

item.getPublishedChannels().then(function (data) {
  console.log('PublishedChannels :', data);
});
item.addChannels(channels, options) channels - Array of channel objects

options - Object with {silent: true|false}

channels - yes

options - optional

Adds given channels to the item.
item.addChannels([{id: '<channel1>', ...}, {id: '<channel2>', ...}]);
item.addChannels([{id: '<channel1>', ...}, {id: '<channel2>', ...}], {silent: true});
item.removeChannels(channels, options) channels - Array of channel objects

options - Object with {silent: true|false}

channels - yes

options - optional

Removes given channels from the item
item.removeChannels([{id: '<channel1>', ...}, {id: '<channel2>', ...}]);
item.removeChannels([{id: '<channel1>', ...}, {id: '<channel2>', ...}], {silent: true});
item.addTags(tags, options) tags - Array of tag objects

options - Object with {silent: true|false}

tags - yes

options - optional

Adds given tags to the item
item.addTags([{name: 'tag1'}, {id: 'tag2'}]);
item.addTags([{name: 'tag1'}, {id: 'tag2'}], {silent: true});
item.removeTags(tags, options) tags - Array of tag objects

options - Object with {silent: true|false}

tags - yes

options - optional

Removes given tags from the item
item.removeTags([{name: 'tag1'}, {id: 'tag2'}]);
item.removeTags([{name: 'tag1'}, {id: 'tag2'}], {silent: true});
item.addCollections(collections, options) collections - Array of collection objects

options - Object with {silent: true|false}

collections - yes

options - optional

Adds given collections to the item
item.addCollections([{id: '<collection1>', ...}, {id: '<collection2>', ...}]);
item.addCollections([{id: '<collection1>', ...}, {id: '<collection2>', ...}], {silent: true});
item.removeCollections(collections, options) collections - Array of collection objects

options - Object with {silent: true|false}

collections - yes

options - optional

Removes given collections from the item
item.removeCollections([{id: '<collection1>', ...}, {id: '<collection2>', ...}]);
item.removeCollections([{id: '<collection1>', ...}, {id: '<collection2>', ...}], {silent: true});
item.addCategories(taxonomy, categories, options) taxonomy - taxonomy under which categories fall

categories - Array of category objects

options - Object with {silent: true|false}

taxonomy -yes

categories - yes

options - optional

Adds given categories under given taxonomy to the item
item.addCategories(<taxonomy>, [{id: '<category1>', ...}, {id: '<category2>', ...}]);
item.addCategories(<taxonomy>, [{id: '<category1>', ...}, {id: '<category2>', ...}], {silent: true});
item.removeCategories(taxonomy, categories, options) taxonomy - taxonomy under which categories fall

categories - Array of category objects

options - Object with {silent: true|false}

taxonomy -yes

categories - yes

options - optional

Removes given categories under given taxonomy from the item
item.removeCategories(<taxonomy>, [{id: '<category1>', ...}, {id: '<category2>', ...}]);
item.removeCategories(<taxonomy>, [{id: '<category1>', ...}, {id: '<category2>', ...}], {silent: true});
item.getFormOptions() None n/a Returns form options
{
    supportsSetName: true|false,
    supportsSetDescription: true|false,
    supportsSetLanguage: true|false,
    supportsSetTranslatable: true|false,
    supportsSetSlug: true|false,
    supportsSetMetaData: true|false,
    supportsSetNativeFile: true|false,
    supportsRequiredValidation: true|false,
    placement: sidebar|drawer,
    mixedValueFields: [<field_name1>, <field_name2>..]
 
}
var formOptions = item.getFormOptions();
item.getNativeFileOptions() None n/a Returns native file options. This is an array of possible options to upload native file. First item in the array allows to upload the file from computer, followed by options that allow to use the file from existing translations.
[{
action: "add-from-computer",
label: "Add from this computer"
value: "add-from-computer"
},
{
action: "add-from-documents",
label: "Add from Documents",
value: "add-from-documents"
},
{
action: "add-from-translation"
label: "Use <Language Name> Master"
languageIsMaster: true
value: <id of master>
},
{
action: "add-from-translation"
label: "Use <Language Name>"
languageIsMaster: false
value: <id of the translation>
}...]
var nativeFileOptions = item.getNativeFileOptions();
item.validateNativeFile() file - instance of File object yes Validates given file object and returns a Promise. When fullfills returns validation object. Validation is done to validate the file type.
// when valid
{
  isValid: true,
}
 
// when invalid
{
  isValid: false,
  errorMessageSummary: <error message>
  errorMessageDetail: <detail error message>
};
This method should be used to validate the chosen file when the 'add-from-computer' option is selected to pick a native file.
item.validateNativeFile(file).then(function (validation) {
  if (validation && validation.isValid) {
    // handle valid
  } else {
    // display invalidation errors
  }
}).catch(function (error) {
  // handle error
});
item.setNativeFile(file, options) file - File objectoptions - Object with {silent: true|false} no Sets the given file This method should be used to set the chosen file when the 'add-from-computer' option is selected to pick a native file.
item.setNativeFile(file);
item.setNativeFile(file, {silent: true});
item.setSourceId(sourceId, options) sourceId - id of the existing translation

options - Object with {silent: true|false}

sourceId - yes options - optional Sets the given sourceId This method should be used to set the sourceId when the 'add-from-translation' option is chosen. Selected translation's id should be passed as souceId.
item.setSourceId(<id>);
item.setSourceId(<id>, {silent: true});
item.openDocumentPicker() None n/a Opens the document picker drawer and returns a Promise. When fullfills returns an object containing id and name of the selected document.
{
    id: <docId>,
    name: <docName>
}
item.openDocumentPicker().then(function (doc) {
   console.log('Selected document:', doc);
  }).catch(function (error) {
    // handle error
});
 
item.validateDocument(doc) doc - document object

{ id: <docId> name: <docName> }

yes Validates given document object and returns a Promise. When fullfills returns validation object. Validation is done to validate the extension of the document name.
// when valid
{
  isValid: true,
}
 
// when invalid
{
  isValid: false,
  errorMessageSummary: <error message>
  errorMessageDetail: <detail error message>
};
This method typically used to validate the chosen document when the 'add-from-documents' option is selected and when the document is chosen from the document picker.
item.validateDocument(doc).then(function (validation) {
  if (validation && validation.isValid) {
    // handle valid
  } else {
    // display invalidation errors
  }
}).catch(function (error) {
  // handle error
});
item.setDocument(doc, options) doc - document object

{ id: <docId> name: <docName> }

options - Object with

{silent: true|false}

yes

doc -yes

options - optional

Sets the given document. This method typically used to set the document when the given document needs to be used for separate native file.
item.setDocument(file);
item.setDocument(file, {silent: true});