Running JavaScript before submitting workflow form
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2015 08:03 AM
Hi,
like the subject says I would like to run JavaScript and call web script before submitting a form. So when the user is pressing the submit button the JavaScript should be run but I just don't know which is the best way to implement this. I've been looking at forms-runtime.js but it is general file for every form in Alfresco and that doesn't seem to be proper place to do my implementation because I only want to use my script when submitting a workflow form. Could somebody point me to the right direction?
Thanks in advance.
like the subject says I would like to run JavaScript and call web script before submitting a form. So when the user is pressing the submit button the JavaScript should be run but I just don't know which is the best way to implement this. I've been looking at forms-runtime.js but it is general file for every form in Alfresco and that doesn't seem to be proper place to do my implementation because I only want to use my script when submitting a workflow form. Could somebody point me to the right direction?
Thanks in advance.
Labels:
- Labels:
-
Archive
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2015 08:30 AM
You can do this by overriding activiti-transitions.js file which is @ path share\components\form\workflow. This file contains a function ActivitiTransitions_onClick which is called when any button in workflow form in clicked. You can add your condition and custom code there.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2015 08:47 AM
Thanks, I will try this right away!
I'll tell here how I'll manage.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2015 06:49 AM
It seems that init form of the workflow is not using activiti-transitions.js file. Now I'm back to using this form-runtime.js but I don't know if this is very smart choice because I should do some hax to detect what form is in use. So that would be done checking if some element is found or not. I wonder how init form handles the transition buttons. If anyone could bring some light to that I would be really happy. I didn't mention earlier I needed this feature for the init form because I didn't know there were differences between them.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2015 06:09 AM
Hi,
I am not quite sure if your feature is global or should apply to specific workflow. If the case is for specific workflow, I have always put my init scripts on the startEvent task of the workflow; which executes upon a transition click. You would just have to handle you code to look out for failures, then you can use the <strong>throws</strong> keyword of javascript to prevent the workflow from starting. But if your case is to happen on workflow select, then you will have to use the process's execution level listener to achieve that.
Hope this is helpful.
I am not quite sure if your feature is global or should apply to specific workflow. If the case is for specific workflow, I have always put my init scripts on the startEvent task of the workflow; which executes upon a transition click. You would just have to handle you code to look out for failures, then you can use the <strong>throws</strong> keyword of javascript to prevent the workflow from starting. But if your case is to happen on workflow select, then you will have to use the process's execution level listener to achieve that.
Hope this is helpful.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 04:50 AM
Hello, I'm having the same problem. Did you made a workaround about this?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2018 04:18 AM
You can try something like this:
<serviceTask id="scripttask1" name="Submit" activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate"> <extensionElements> <activiti:field name="script"> <activiti:string><![CDATA for(var i = 0; i < bpm_package.children.length; i++) { var node = bpm_package.children[i]; var isRegistered = node.properties["myfirm:isRegistered"]; if(isRegistered==true) { throw new Error ("The document has already been registered"); } } ]]></activiti:string> </activiti:field> <activiti:field name="runAs"> <activiti:string><![CDATA[admin]]></activiti:string> </activiti:field> </extensionElements> </serviceTask>
Regards.
