Alan
Alan

Reputation: 526

Alfresco: update data list line

I have data being sent to a custom data list from the following code:

// Get the site name and dataLists 
var site = siteService.getSite("Testing");
var dataLists = site.getContainer("dataLists");

// Check for data list existence 
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();
}

// Create new data list variable 
var orpList = dataLists.childByNamePath("orplist1");

// If the data list hasn't been created yet, create it
if (!orpList) {
  var orpList = dataLists.createNode("orplist1","dl:dataList");

  // Tells Alfresco share which type of items to create
  orpList.properties["dl:dataListItemType"] = "orpdl:orpList";
  orpList.save();

  var orpListProps = [];
  orpListProps["cm:title"] = "Opportunity Registrations: In Progress";
  orpListProps["cm:description"] = "Opportunity registrations that are out for review.";
  orpList.addAspect("cm:titled", orpListProps);
}

// Create new item in the data list and populate it                              
var opportunity = orpList.createNode(execution.getVariable("orpWorkflow_nodeName"), "orpdl:orpList");
opportunity.properties["orpdl:nodeName"] = orpWorkflow_nodeName;
opportunity.properties["orpdl:dateSubmitted"] = Date().toString();
opportunity.properties["orpdl:submissionStatus"] = "Requires Revisions";
opportunity.save();

This correctly creates data list items, however, at other steps of the workflow require these items to be updated. I have thought of the following options:

Unfortunately I have not found adequate solutions elsewhere to either of these options. I attempted to use orpWorkflow_nodeName, which is a unique identifier generated at another step, to identify a node to find it. This does not seem to work. I am also aware that nodes have unique identifiers generated by Alfresco itself, but documentation doesn't give adequate information on how to obtain and use this.

My question:

Instead of var opportunity = orpList.createNode(), what must I use in place of createNode() to identify an existing node so I can update its properties?

Upvotes: 1

Views: 499

Answers (1)

mitpatoliya
mitpatoliya

Reputation: 2037

You can use this to check existing datalist item.

var opportunity = orpList .childByNamePath(execution.getVariable("orpWorkflow_nodeName"));

// If the data list Item is not been created yet, create it
if (!opportunity ) {
  var orpList = orpList .createNode(execution.getVariable("orpWorkflow_nodeName"),"dl:dataList");}

Upvotes: 1

Related Questions