Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 12:39 PM
I have a one-button script, like this:
function replan_button() {
g_form.setValue('u_replan', true);
g_form.setValue('state', 1);
g_form.clearValue('due_date');
g_form.setMandatory('comments', true);
g_form.addInfoMessage('Insira uma justificativa para o replanejamento, preencha a nova Data de vencimento e salve o registro');
// Obter o valor atual do campo 'u_number_of_replannings'
var currentCount = parseInt(g_form.getValue('u_number_of_replannings'), 10) || 0;
// Incrementar o valor
var newCount = currentCount + 1;
// Atualizar o campo com o novo valor
g_form.setValue('u_number_of_replannings', newCount);
g_form.setValue('u_replan', false);
}
This code, when clicking on the button, should increase the "u_number_of_replannings" field by 1, but it is not increasing the amount. Could anyone help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 01:04 PM
@lucasmeneze If you want the incremented value to be immediately saved to the database, consider calling g_form.save() at the end of your script. This ensures all changes, including the incremented value, are persisted.
please mark my response as helpful 👍and accept the solution✅ if that help me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 01:22 PM
I suggest that you change line:
var currentCount = parseInt(g_form.getValue('u_number_of_replannings'), 10) || 0;
to
var currentCount = parseInt(g_form.getValue('u_number_of_replannings'), 10);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 01:32 PM
The button is working properly now, but when I keep clicking the button it increases the quantity every time I click, whereas it was only supposed to increase by 1, we are thinking about making a division using serve-side, would there be any option?