cancel
Showing results for 
Search instead for 
Did you mean: 

Start workflow via JavaScript with the help of rules

fbehfar
Champ on-the-rise
Champ on-the-rise
Hi,
I want to create a rule, with the "execute a script" actions. I want to start the advanced workflow with the help of the rules.

Actually I want to automaticly start the workflow by adding a new content.

for example:
a user adds a content
the (whitepaper) workflow starts in backgroound and send a task for a specific users,
these users recieve a task on their pool tasks list.

Is it possible to start a workflow by defining a rule, at the time of adding a new content????
I guess one solution is to use the javascript in the rule definition, but how should the script look like?

Thank you,
FSB
34 REPLIES 34

mikef
Champ in-the-making
Champ in-the-making
The following example JavaScript starts the out-of-the-box adhoc workflow, assigns the task to the 'admin' user and sets the due date to 3 days time. You will obviously need to substitute workflowName and bpm:assignee with the details for your worklow.

var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "jbpm$wf:adhoc";
workflow.parameters["bpm:workflowDescription"] = "The attached document has been uploaded to Alfresco. Please review within 3 days.";
workflow.parameters["bpm:assignee"] = "admin";
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 3);
workflow.parameters["bpm:workflowDueDate"] = futureDate;
workflow.execute(document);

fbehfar
Champ on-the-rise
Champ on-the-rise
Thank you Mike,

I could start my workflow with the help of your code.
but I don't want to hard code the value of the aspects, for example I want the 'bpm:assignee' be stable, and when the workflow starts automatically, at that time I wanna be able to assign the person, or any other values, like dates, Description or any other values.

How can I do that???

Thank you,
FSB

mikef
Champ in-the-making
Champ in-the-making
It depends on how you want provide the value for these variables. Are you looking to provide UI that the user needs to fill in.

fbehfar
Champ on-the-rise
Champ on-the-rise
Hi,
ya, exactly, I want to provide a UI for getting that values from the user.
Is there any other solution, except UI, and also hard coding?
and for assigning a task to multiple user, should we write like these??

workflow.parameters["bpm:assignees"] = "admin, X, Y";


Thank you again,
FSB.

mikef
Champ in-the-making
Champ in-the-making
There are at least 3 ways you could implement the UI:

1) Write your own JSF UI component that displays a form to capture the data and execute your workflow.

2) Call a custom HTML form that captures the data and posts it to a web script that uses the form data to execute the workflow.

3) Capture the relevant workflow data on the document itself. i.e your document could have a 'reviewers' property (maybe defined by an aspect that is applied to document). Your 'start workflow' Javascript rule could read this data from the document properties and use this as the parameters to execute the workflow.

The best approach depends on your use case, Alfresco and Java knowledge. Option 3 probably requires the least amount of coding….

claudio_martins
Champ in-the-making
Champ in-the-making
You could also create your own Wizard/Dialogs to request data from the user and use it on your workflow.

Have a look at the following wiki page:

http://wiki.alfresco.com/wiki/Dialog_And_Wizard_Framework

fbehfar
Champ on-the-rise
Champ on-the-rise
Thank you so much Mike and claudio.

Mike's help was usefull and Claudio's completed it!

Thank you again
FSB,

kranthi
Star Contributor
Star Contributor

How You did this one? can you give me idea..

wps07032
Champ in-the-making
Champ in-the-making
Hi,

In the sample script posted here, it uses "document" object directly.  For some reason, I keep getting error of "ReferenceError: 'document' is not defined".  I was told that 'document' is one of the root object that is not available to web script JS scripts.  Is there some other way to provide a file to the execute() method.  I'm hoping to achieve passing a file that is already exist in the repository.

Much appreciate any suggestion.

Thanks.