Script

lucasmeneze
Tera Contributor

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?

 

3 REPLIES 3

Satishkumar B
Giga Sage
Giga Sage

@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

Bert_c1
Kilo Patron

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);

lucasmeneze
Tera Contributor

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?