cancel
Showing results for 
Search instead for 
Did you mean: 

Start Workflow Javascript

sweep
Champ in-the-making
Champ in-the-making
Hi,
i tried the solution proposed in wiki to create an advanced workflow when a new document is added to a space.

In the javascript the  assignee of the first task is defined as:
workflow.parameters["bpm:assignee"] = person;

Now in the case of the review workflow give this result: a user auto-review.


I tried different ways to add another user as assignee, but the final result is always an error.

Can you please post an example (also in the Wiki)? I think the advance workflow is useless if a user has to repost everytime all the data.

Thank you,
Marco
7 REPLIES 7

davidc
Star Contributor
Star Contributor
Now in the case of the review workflow give this result: a user auto-review.

What do you mean?

I tried different ways to add another user as assignee, but the final result is always an error.

What's the error?

Can you please post an example (also in the Wiki)? I think the advance workflow is useless if a user has to repost everytime all the data.

What do you mean by 'repost everytime all the data.'?

The parameter "bpm:assignee" must be a person node i.e. the node of the person you want to assign the workflow to.  The tricky bit is getting hold of the appropriate person object.  Obviously, which person depends on what you want to achieve.  But, you could hold the person as a property on the space etc it depends on how you want to specify people for the workflow.  The example in the WIKI keeps it simple by using the person who triggered the rule - simple but, I agree, mostly not very practical.

Something we can do to make life slightly easier is allow "bpm:assignee" to be a simple string holding the username - I'll look at adding this.

I'll also look to improve the example in the WIKI.

Future, we'd like to support assignment of workflow people based on their role in a space.  This could of been done in javascript, but unfortunately, it's not possible to get the space members in Alfresco v1.4 Javascript.

sweep
Champ in-the-making
Champ in-the-making
Now in the case of the review workflow give this result: a user auto-review. What do you mean?
If I use workflow.parameters["bpm:assignee"] = person; the person who is starting the workflow is also the reviewer.

I tried different ways to add another user as assignee, but the final result is always an error.
I don't understand which form the person node must have in the javascritpt. I tried to print the person node of different users using the javascript. I obtained strings like this "workspace://SpacesStore/88f1a516-64d9-11db-b0fa-37ac322390ef".
If I replace person with that string and I add a document to the space using a different user I obtain an error like this:

"Failed to execute script 'workspace://SpacesStore/0bc11081-64e2-11db-b0fa-37ac322390ef': Wrapped org.alfresco.service.cmr.workflow.WorkflowException: Failed to signal transition '' from workflow task 'jbpm$100' (AlfrescoScript#9) "

I also looked for ways to obtain a user node starting from username in the Javascript API but there's no way to do this, isn't it?
Yes, usernames and usergroups instead of nodes would be fantastic.

Waiting for this implementation, what do I have to do to assign tasks to person and group using javascript?

I think the advance workflow is useless if a user has to repost everytime all the data.
The problem is that if I use workflow, I don't want to leave the user the chance to start the process and to choose the reviewer. If you give this opportunity to users the workflow is completely useless. it doesn't force persons to do things in the right way.

One more thing.
Workflows are connected to content. But if I delete a document the workflows and tasks are not deleted.

Yesterday after 3 hours of tests I deleted all the documents.
Then I had to delete tasks for every user, using different username and password to access their lists of tasks. Is this a standard feature or a bug?

Thank you for help,
Marco

davidc
Star Contributor
Star Contributor
If I use workflow.parameters["bpm:assignee"] = person; the person who is starting the workflow is also the reviewer.

That's correct, it's a very simple example piece of javascript - but not very practical.  I will change this.

I don't understand which form the person node must have in the javascritpt.

It must be a javascript Node.

I also looked for ways to obtain a user node starting from username in the Javascript API but there's no way to do this, isn't it?

Having just looked at the Javascript API in more detail, you're right, it's impossible to get hold of people nodes, which is rather important for this particular use case.

The problem is that if I use workflow, I don't want to leave the user the chance to start the process and to choose the reviewer.

Understand.  You want to completely automate "start workflow".  That's the point of the script, but accessing person nodes in javascript is not possible.  So, there's a block.

I think we need to make life easier here by either adding people support to Javascript or allowing simple username strings.  I'll look into providing one or the other - what is your preferred option?  I quite like adding people support to Javascript, in particular getting hold of the space members (perhaps by space role).

Workflows are connected to content. But if I delete a document the workflows and tasks are not deleted.

That's the intended behavour for now.  We need to ensure we understand the appropriate behaviour before implementing.  I don't think it's as simple as deleting workflows when content is deleted.  There may be many content items being routed through the workflow.   The workflow itself may delete content etc.  What behaviour would you like to see?

There's a workflow console which allows you to delete "in-flight" workflows and all associated tasks as an administrator.  This is described at:

http://wiki.alfresco.com/wiki/Workflow_Console

Btw, thanks for all your comments - it helps to improve the features.

sweep
Champ in-the-making
Champ in-the-making
David,
thank you for your replly.

I think we need to make life easier here by either adding people support to Javascript or allowing simple username strings. I'll look into providing one or the other - what is your preferred option? I quite like adding people support to Javascript, in particular getting hold of the space members (perhaps by space role).

Javascript with simple username and groupname strings are an easy and fast to use solution. Coming to workflow maximum flexibility is useful and I think tha javascript is a good choice.

Some examples would help most of workflow users. An example should include a sequence of at least 3 tasks (one using users and one using  groups) with some behaviours to illustrate how to access the workflow space and content nodes during the process definition.

Examples:
1) a script to access workflow document node and move (or copy) the document in another space, when a user approves it or delete it when it is not approved (not common but useful for other scopes 😉 );
2) a script to avoid document editing by other users (checkin - checkout by the initiator?) during the workflow
3) a script to start another workflow when a certain condition verify;

Another example useful example could include a way to "kill" or alter a workflow. Example I start a workflow but then I find an error and I want to restart the flow or alter it.

I think the javascripts are easy to use (also by non-technical persons, ie web designers), if you publish some examples and incentivate other users  to post their examples you can get a lot of insights before developing the workflow wizard.

Coming to my initial problem:
If I understood correctly when you say:
It must be a javascript Node.

and then
That's the point of the script, but accessing person nodes in javascript is not possible. So, there's a block.

you mean, I have no chance to do what I want to do using javascript.

Is there another way (also a "dirty" wat) to create a workflow. Is it possible to create different process definition XML and incapsulate in XML the user (or group) nodes or usernames?

It's my last chance to make it work…

Thank you again and let me know if you need help in defining a complete example workflow. I really would like to help you in any way if I can (unfortunately java is not my friend…).

Marco

davidc
Star Contributor
Star Contributor
Is there another way (also a "dirty" wat) to create a workflow.

It's not the end of the world 🙂

There are two possible approaches of getting hold of the assignee person…

1) Define a custom space type which has an association to person.  Then define a custom property page for that space that allows an end-user to select who is the assignee.  This would give a simple UI to customise the workflow.  Then in the start workflow action script you can use something like:

  …["bpm:assignee"] = space.assocs["custom:workflowAssignee"][0];

2) Issue a lucene search:

   Something like…

  …["bpm:assignee"] = search.luceneSearch("@cm\:username:\"fredb\"") ;


Re: examples: we're working on some more sample workflow definitions including using javascript within the workflow definition to perform operations against the content being routed through the workflow.

I'd be happy to help build out a workflow definition (which is just XML & Javascript by the way - no Java) if you can provide a specification of the workflow you're trying to implement.  Perhaps then it can become another sample.

sweep
Champ in-the-making
Champ in-the-making
Hi David,
I tried your second solution but it doesn't work. I receive always the same message. Is the syntax to search a user using Lucene correct?

I'm going to try the first one.
My workflow has three users (group of users) 1, 2 , 3 and 4.
1) the first one (user 1) create/add a document and start the workflow.
The workflow moves to step 2 and users 2 and 3 receive an email message.
The document is not editable.

2) in this step I have two users (2 and 3) who have to approve in parallel the document.

If one of the two users don't approve, the workflow move to step 1 and an email message goes to users 1, 2 and 3.

If both users approve, the workflow move to step 3 and an email message goes to users 1, 2 and 3. User 4 receive another email message.
The document is moved to a folder accessible by user 4 and is always not editable.

3) in this step I have one user (4) who has to approve the document.

If user 4 doesn't approve, the workflow move to step 1 and an email message goes to users 1, 2 and 3.
The document is moved back to initial folder (Draft)

If both users approve, the workflow move to step 3 and an email message goes to users 1, 2 and 3. User 4 receive another email message.
The document is moved to a final folder and is again editable.
The workflow ends and all users receive a final email message.

In this case I have to add different assignees (4 users - roles) to create the workflow, isn't it?

I try to create this and then post you back my file.

Thank you again,
Marco

davidc
Star Contributor
Star Contributor
I was too keen on the search solution.  After testing to get the correct query syntax, it became obvious that the 'search' variable is not available in workflow javascript.

I've just added 'search' capability to workflow javascript and tested with the following query:

var nodes = search.luceneSearch("@cm\\:userName:\"admin\"");
logger.log(nodes.length);
logger.log(nodes[0].name);

I'll check-in the above to allow solution 2 in future releases.

Thanks.