cancel
Showing results for 
Search instead for 
Did you mean: 

Auto launch workflow when a document is added to Alfresco

stallapragada
Champ in-the-making
Champ in-the-making
Hi

I have created a custom document approval workflow and am able to manually launch it from Alfresco Web Client. I would want to know if there is any way of auto launching the workflow whenever the document is added / checked in to Alfresco.

I have read somewhere that you can define a set of rules in the space to invoke a javascript that inturn launches the custom workflow. I would want to see any working example if any of you guys have it.

Thanks for your help.

Srikant
Principal Consultant
IntrospeQt Software India Pvt Ltd.
http://www.introspeQt.com
6 REPLIES 6

stallapragada
Champ in-the-making
Champ in-the-making
Ok. I have figured this one out.

All you need to do is create a js file with the following contents.

var workflow = actions.create("start-workflow"); 
workflow.parameters.workflowName = "jbpm$dcwf:leaveapproval";  //This is your workflow name as defined in processdefinition.xml
workflow.parameters["bpm:workflowDescription"] = "Approve my leave";
workflow.parameters["dc:empId"] = "1445"; //set workflow property values
workflow.parameters["dc:empName"] = "Srikant";
workflow.execute(document);

Save this file and check it in into Alfresco under /Company Home/Data Dictionary/Scripts folder.

Go to your space where you would want to run the rule. Create a rule and specify the "Action" as "Execute a script" and select this js file from the dropdown.

You should be ready to go once you have saved your rule.

-Thanks
Srikant
Principal Consultant
IntrospeQt Software India Pvt Ltd.
http://www.introspeQt.com

fbehfar
Champ on-the-rise
Champ on-the-rise
Hi,
I have done all the mentioned steps, but I got a permission error when I want to add a new content!!!
before I specify that rule, I could easily add a content (the user role is collaborator), but after specifying that rule in that space, I got this error:

Please correct the errors below then click OK.

    * A system error happened during the operation: Failed to execute script 'workspace://SpacesStore/fe078d96-27e7-11de-b51d-2bf81e7cd3ea': Access Denied. You do not have the appropriate permissions to perform this operation.

What's my problem? what should I do? Smiley Sad
would you help me!

thanks,
FSB

sathish
Champ in-the-making
Champ in-the-making
Hi,
   I guess your work flow script is unable to execute a particular part since the user does not have appropriate permission to the execution of the script.

Try running the script inside your processdefinition.xml as admin. It might solve your problem
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <runas>admin</runas>
            <script>
               // your script which causes the error
            </script>
</action>

Sathish
Senior Consultant
Tejas Technologies

fbehfar
Champ on-the-rise
Champ on-the-rise
Hi,
Actually I want a workflow to be run in a space, in which I have created a rule. The workflow that i need is Adhoc.

this is the script that I use to run the workflow:

var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "jbpm$wf:adhoc";
workflow.parameters["bpm:workflowDescription"] = "A new content has been added in Draft.";
workflow.parameters["bpm:assignee"] = people.getPerson("someone");
workflow.execute(document);

I put this code in a .js file and save it in the Data Dictionary>Scripts space. and created a rule, which runs this script in that specific space whenever a new content is added!
Before I create the rule, I can simply add a new content without any error but after creating one, I get the above mentioned permission errorSmiley Sad
please help me in this matter, I'm getting crazy about it, because i see no fault!

thanks
FSB

stallapragada
Champ in-the-making
Champ in-the-making
Couple of things I need to know.

1. Which space did you create this rule and does the user who is adding the document to this space has necessary privileges on this space?

2. You might want to put some log messages and see if the javascript is being executed at all.
var backupFolder = space.childByNamePath("Backup");
if (backupFolder == null && space.hasPermission("CreateChildren"))
{
   // create the folder for the first time
   backupFolder = space.createFolder("Backup");
}

   var logFile = backupFolder.childByNamePath("backuplog1.txt");
   if (logFile == null)
   {
      logFile = backupFolder.createFile("backuplog1.txt");
   }
   if (logFile != null)
   {
      logFile.content += "starting logging " ;
   }

Put appropriate log messages and you can see this file under backup folder. This might give you some insight. Just to give you a comfort feeling, your js file is working fine for me. I have imported it and am able to launch the adhoc workflow on addition of a document to alfresco.

-Thanks
Srikant
Principal Consultant
IntrospeQt Software India Pvt Ltd
http://www.introspeQt.com

vidya_r
Champ in-the-making
Champ in-the-making
Is there any way I can apply the adhoc workflow for a whole space as such. i.e  review a space etc, approve a space ?