Alfresco: creating a Javascript data list

I am trying to execute Javascript in an Alfresco workflow to create a custom data list type on my site called Testing. But before filling in the custom data type information, I tried to simply create a contact list data list based on the examples I found to make sure it works.

Here is my code:

var site = siteService.getSite("Testing");
var dataLists = site.childByNamePath("dataLists");

if (!dataLists) {
  var dataLists = site.createNode("dataLists", "cm:folder");

  var dataListProps = new Array(1);
  dataListProps["st:componentId"] = "dataLists";
  dataLists.addAspect("st:siteContainer", dataListProps);
  dataLists.save();

  logger.log("Created new datalists folder.");'
}

var contactList = dataLists.childByNamePath("contactlist1");

if (!contactList) {
  var contactList = dataLists.createNode("contactlist1","dl:dataList");

  // tells Share which type of items to create
  contactList.properties["dl:dataListItemType"] = "dl:contact";
  contactList.save();

  var contactListProps = [];
  contactListProps["cm:title"] = "My Contacts";
  contactListProps["cm:description"] = "A contact list generated by a javascript.";
  contactList.addAspect("cm:titled", contactListProps);

  logger.log("Created contact datalist.");

}

var contact = contactList.createNode(null, "dl:contact")
contact.properties["dl:contactFirstName"] = "Florian";
contact.properties["dl:contactLastName"] = "Maul";
contact.properties["dl:contactEmail"] = "info@fme.de";
contact.properties["dl:contactCompany"] = "fme AG";
contact.properties["dl:contactJobTitle"] = "Senior Consultant";
contact.properties["dl:contactPhoneMobile"] = "not available";
contact.properties["dl:contactPhoneOffice"] = "not available";
contact.properties["dl:contactNotes"] = "Alfresco Expert";
contact.save();
logger.log("Created new contact: " + contact.nodeRef);

      

I am assuming that it is not picking the correct site, but I am not sure how else to set the site variable to the Testing site. Also, I know that this code is in the right place in my .bpmn file because the other Javascript is working correctly there.

What's wrong with my code?

+3


source to share


1 answer


There are 2 javascript objects on which you have your confusion. One is site

and the other is node

. The Site object does not have a method called childByNamePath

.

Use below to get data instead.



var dataLists = site.getContainer("dataLists");

      

Your site search code is correct. The only change for datalist.

+2


source







All Articles