Hi!
I want to generate automatically an ID based on the number of existing tasks in the BD, so I thought about using camForm.on('submit')
event to manage it. This is what I do:
camForm.on('submit', async function(evt) {
try {
// getHistoryTaskCount makes an API call to GET history/task/count to return the number of tasks created in the system
var response = await $scope.getHistoryTaskCount();
var numTasks = response.data.count + 1;
// To have 0001, 0002, 0003, and so forth
var lastTaskId = ("0000"+numTasks.toString()).substr(-4);
// This is the ID we want to store in the variable 'id' of the form
var newTaskId = 'C-'+new Date().getFullYear().toString()+'-'+lastTaskId;
// Set the form variable value
camForm.variableManager.variableValue('id', newTaskId);
// This prints ID: C-2019-0032, C-2019-0033, etc... (CORRECT VALUE)
console.log("ID: ", camForm.variableManager.variableValue('id'));
} catch(e) {
// Error in API call
alert("Couldn't assign an automatic ID");
evt.submitPrevented = true;
}
// etc...
});
The problems I’m having:
- The new task is always created with empty
id
, although theconsole.log
in the code above prints the rightid
values - The form is always submitted, even if I set
evt.submitPrevented = true;
(I realized about this in my tests, when I didn’t want to finish the submission, only print some test messages)
Any idea on what’s going on? Thanks!