cancel
Showing results for 
Search instead for 
Did you mean: 

Workflow execute needs nodeRef?

sgartner
Champ on-the-rise
Champ on-the-rise
I'm trying to start my custom workflow from JavaScript with the code below.  I get the error that the workflowAction.execute() requires a nodeRef.  I've tried passing the document object as well as document.nodeRef, but neither seems to satisfy it.  I've walked through the script in the debugger and everything seems to be correct up to the execute. 

The web script call looks like this:
http://localhost:8080/alfresco/wcs/test/startWorkflow?nodeid=d8d0a561-093d-4492-a124-9fb63369fae2

The log shows:
Executing script /test/startWorkflow.get.js (in classpath store file:C:/Alfresco/tomcat/shared/classes/alfresco/extension/templates/webscripts)

nodeId = d8d0a561-093d-4492-a124-9fb63369fae2

theDocument = Node Type: {http://www.alfresco.org/model/content/1.0}content, Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/application/1.0}inlineeditable, {http://www.alfresco.org/model/content/1.0}titled, {http://www.alfresco.org/model/content/1.0}author]

theDocument nodeRef = workspace:/ /SpacesStore/d8d0a561-093d-4492-a124-9fb63369fae2

Attached JBPM Context to transaction 4d7d09fc-2917-407c-8373-157e14646314

Caught exception; decorating with appropriate status template : org.alfresco.scripts.ScriptException: 04170028 Failed to execute script '/test/startWorkflow.get.js (in classpath store file:C:/Alfresco/tomcat/shared/classes/alfresco/extension/templates/webscripts)': NodeRef must be supplied.

Can anyone tell me what is wrong with this code?


var nodeId = args.nodeid;

logger.log("nodeId = " + nodeId);

// var document = utils.getNodeFromString("workspace://SpacesStore/" + nodeId);
var theDocument = search.findNode("workspace://SpacesStore/" + nodeId);

logger.log("theDocument = " + theDocument);
logger.log("theDocument nodeRef = " + theDocument.nodeRef);

var workflowAction = actions.create("start-workflow");
workflowAction.parameters.workflowName = "jbpm$nmwf:MyWorkflow";
workflowAction.parameters["bpm:workflowDescription"] = "Please edit: " + theDocument.name;
workflowAction.parameters["bpm:assignees"] = [people.getPerson("admin"), people.getPerson("joebloe")];
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 7);
workflowAction.parameters["bpm:workflowDueDate"] = futureDate;
workflowAction.parameters["bpm:dueDate"] = futureDate;
// workflowAction.execute(theDocument);
workflowAction.execute(theDocument.nodeRef);
workflowAction.signal();

Thanks in advance,
3 REPLIES 3

sgartner
Champ on-the-rise
Champ on-the-rise
I would still like to know why the previous (Alfresco specific) code doesn't work (so I'm not going to mark it solved yet), but it turns out doing it the long way works just fine (in theory this is what the action used above is doing):


var nodeId = args.nodeid;
var theDocument = search.findNode("workspace://SpacesStore/" + nodeId);

var workflowDefinition = workflow.getDefinitionByName("jbpm$nmwf:myWorkflow");

var workflowPackage = workflow.createPackage();
workflowPackage.addNode(theDocument);

var workflowParameters = [];
workflowParameters["bpm:workflowDescription"] = "Please edit: " + theDocument.name;
workflowParameters["bpm:assignees"] = [people.getPerson("admin"), people.getPerson("joebloe")];
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 7);
workflowParameters["bpm:workflowDueDate"] = futureDate;
workflowParameters["bpm:dueDate"] = futureDate;
workflowParameters["bpm:workflowPriority"] = 1;

var workflowPath = workflowDefinition.startWorkflow(workflowPackage, workflowParameters);

// This does *not* work, I get "bpm_assignees is not defined"
// workflowPath.signal(null);

// End the start task
var tasks = workflowPath.getTasks();
for (task in tasks)
  {
   tasks[task].endTask(null);
  }

jc09
Champ in-the-making
Champ in-the-making
Just a little up to know if someone has make progress on this problem ?

sgartner
Champ on-the-rise
Champ on-the-rise
Just a little up to know if someone has make progress on this problem ?

I never learned anything more about this problem.  We are still using the code I posted last.  If you find anything, please do update this thread.