Skip to main content
slight grammar fix to the question title
Link
Glenn Stevens
  • 1.9k
  • 2
  • 18
  • 33

How to create a component within the Tridion JS Framework (Anguilla)?

Tweeted twitter.com/#!/StackTridion/status/646712860396154880
Source Link

How to create component with Tridion JS Framework (Anguilla)?

I am working on an extension that must create a component. Until now, my code looks like this:

var item = $models.createNewItem($const.ItemType.COMPONENT);
item.setPublication(pubId);
item.setOrganizationalItem(folderId);
item.setDefaultSubType($const.ComponentSubType.COMPONENT);
item.setSchema(schemaId);
item.setTitle("Test Title");

$evt.addEventHandler(item, "save", HandlerSave);
$evt.addEventHandler(item, "savefailed", HandlerSaveFailed);
$evt.addEventHandler(item, "validatefailed", HandlerValidateFailed);

item.setChanged(true);
item.save(false);

The error I get is: Unable to load XML: XML document must have a top level element.. Unable to update Component (tcm:0-0-0).

I think the problem is creating the xml. I tried with setXml/setContent..., but I don't know how to build the required xml for the component.