Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alfresco: Javascript data list creation

I am attempting to execute some Javascript in my Alfresco workflow to create a custom data list type in my site called "Testing". But before I fill in my custom data list type information, I tried simply creating a contact list data list based on 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"] = "[email protected]";
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);

My guess is it's not selecting the right site, but I'm not sure how else to set the site variable to the "Testing" site. Also, I know this code is in the right place in my .bpmn file, because other Javascript in there executes correctly.

What is wrong with my code?

like image 994
Alan Avatar asked Dec 14 '25 02:12

Alan


1 Answers

There are 2 javascript object on which you have confusion.One is site and other is node.Site object does not have method called childByNamePath.

Instead of that use below for getting datalist.

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

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

like image 186
Krutik Jayswal Avatar answered Dec 16 '25 17:12

Krutik Jayswal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!