cancel
Showing results for 
Search instead for 
Did you mean: 

Starting a workflow by webscript

sihnu
Champ in-the-making
Champ in-the-making
Greetings,

I've been practicing with a web script that is supposed to take workflow definition name as a parameter and start a workflow of that definition. Here is my code:


var definition,
name;

if (url.templateArgs['name'] === null) {
   status.code = 400;
   status.message = "A name must be provided.";
   status.redirect = true;
} else {
   name = url.templateArgs['name'];
}

definition = workflow.getDefinitionByName(name);
definition.startWorkflow(new Array());


I'm don't want to set any properties or package items at this point. All I want is to start a workflow but I get an error:

<blockquote>"org.springframework.extensions.webscripts.WebScriptException - 00290014 Wrapped Exception (with status template): 00290080 Failed to execute script '\/startWorkflow.get.js (in repository store workspace:\/\/SpacesStore\/Company Home\/Data Dictionary\/Web Scripts Extensions)': null",</blockquote>

when I'm calling the webscript. I debugged the java code behind this and I can see the null pointer error occurs at this point (method public JscriptWorkflowPath startWorkflow(ScriptNode workflowPackage, Object properties) at class: JscriptWorkflowDefinition):


Serializable context = workflowParameters.get(WorkflowModel.PROP_CONTEXT);
if (context == null)
{
    workflowParameters.put(WorkflowModel.PROP_CONTEXT, workflowPackage.getNodeRef());
}


workflowPackage is null. It's supposed to be null because I am not passing any documents. To get rid of this problem context should not be null. So I should set context as a property. The problem is I don't have any idea what is this context supposed to be. Could anyone help how to figure out what the context is supposed to be for me or some other way to solve the problem?

Thanks in advance…
3 REPLIES 3

mlagneaux
Champ on-the-rise
Champ on-the-rise
I think that's mandatory to pass a workflowPackage. In your case, this workflowPackage, which is a folder, won't have any children.

sihnu
Champ in-the-making
Champ in-the-making
Thanks for the reply, I think I have confused workflowPackage with itemPackage… What is workflowPackage? When you start workflow using Share user interface you don't usually bind any folders to it. I'm kind a clueless what I should pass there.

sihnu
Champ in-the-making
Champ in-the-making
Hey,

I did some googling about workflow package and I got now better understanding of it. So I updated my javascript with this:



definition = workflow.getDefinitionByName(name);
var workflowPackage = workflow.createPackage();
definition.startWorkflow(workflowPackage, new Array());



And it works now. Thanks for the help. It lead me to solve the problem Smiley Happy