12-20-2016 10:57 AM
Has anyone successfully implemented a way to auto-save the data entered by an end user in the Form while they execute their assigned User Task?
I'm building an app in Activiti Enterprise 1.5.2. Out-of-the-box, it will only save the form data when an end user deliberately clicks the save button at the top or bottom of the form. If they navigate away from their Task without clicking save, they will lose all the data they entered.
The closest I've come is using scope.saveForm(); in Javascript, but every time it's called, it refreshes the form, which takes the focus away from where the end user was on the form. If the end user was at the bottom of the form, the refresh brings them all the way back up to the top. That's bad UX, so this won't work.
I'm new to Activiti, so I'm not familiar with all of its guts, but maybe it's possible to customize the saveForm() function to skip the form refresh?
Any thoughts from the community would be greatly appreciated. Thanks.
-Joe
12-21-2016 11:59 AM
Hello Joe,
Use the following javascript in one one or many of the Activiti JS hook points such as formFieldValueChanged(), formFieldFocus(), formFieldBlur() etc. Refer Alfresco Activiti for more details on these extension points. To enable auto-save across the activiti instance, add this logic to activiti-app/workflow/extensions/render-form-extensions.js. If you need this feature in just a few forms, add it to the "Javascript" tab in the Form Designer.
//Doing this check to exclude Start Forms.
if(scope.formData.taskId){
//Create POST Data
var postData = scope.createPostData();
//Extract Task ID
var taskId = scope.formData.taskId
//Get FormService
var formService = angular.element(document.body).injector().get('FormService')
//Call the Save API
formService.saveTaskForm(taskId, postData)
}
12-21-2016 11:59 AM
Hello Joe,
Use the following javascript in one one or many of the Activiti JS hook points such as formFieldValueChanged(), formFieldFocus(), formFieldBlur() etc. Refer Alfresco Activiti for more details on these extension points. To enable auto-save across the activiti instance, add this logic to activiti-app/workflow/extensions/render-form-extensions.js. If you need this feature in just a few forms, add it to the "Javascript" tab in the Form Designer.
//Doing this check to exclude Start Forms.
if(scope.formData.taskId){
//Create POST Data
var postData = scope.createPostData();
//Extract Task ID
var taskId = scope.formData.taskId
//Get FormService
var formService = angular.element(document.body).injector().get('FormService')
//Call the Save API
formService.saveTaskForm(taskId, postData)
}
12-22-2016 04:43 PM
Boom! That did it. Thanks!
NOTE to anyone who decides to add this code to their Activiti instance:
Thru working with Ciju, I found out that every time the app saves the data in a form, the SAVED_FORM table in the database gets a new row. So, if you execute a save every time formFieldValueChanged() is triggered, a new row is added to the SAVED_FORM table. That's especially bad for text fields because it would add a new row for every letter typed into the text box. That would get out of hand very fast in our app. Personally, I think formFieldFocus() or formFieldBlur() are better places to use it. Also, consider adding a maintenance job in your database to delete unneeded saves.
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.