Skip to main content
November 23, 2025
Answered

Error transferring a number from one function to another.

  • November 23, 2025
  • 2 replies
  • 1069 views
 
I have an extra date calculation and I need a solution. The `calculo2` function is a number calculated in the previous item, but I need it to be copied to a location in the `DPP` function, and I'm not able to do that. When I put the number in, it works, but it doesn't pull it from the previous `calculo2` function.
 
This works:
 
// Define o número de dias a ser adicionado
var diasParaAdicionar = 35;

// Obtém o valor do campo "Date1" como string
var sDate1 = this.getField("Date1").valueAsString;

// Verifica se o campo inicial está vazio
if (sDate1 === "") {
event.value = ""; // Limpa o campo atual se o inicial estiver vazio
} else {
// Converte a string da data para um objeto Date do JavaScript,
// especificando o formato (neste exemplo, "mm/dd/yyyy")
var d1 = util.scand("mm/dd/yyyy", sDate1);

// Adiciona os dias à data. O método setDate() lida automaticamente
// com a virada de mês e ano, se necessário.
d1.setDate(d1.getDate() + diasParaAdicionar);

// Formata a nova data de volta para uma string no formato desejado
// e define o valor do campo atual
event.value = util.printd("mm/dd/yyyy", d1);
}
 
Now, this number 35 comes from a previous calculation: 280 - Calculation1 which I'm having trouble retrieving. It always requires editing and typing the number, which isn't working. Can someone help me?
 
Correct answer ls_rbls

Good morning friend. I couldn't solve it. I did everything correctly, but the date I want isn't showing up, that is, x days from any given date.

 

// Defines the number of days to be added
var daysToAdd = Number(this.getField("Calculation2").value);

 

And I did the calculations in the correct order.

Lucidio

 


Hi @lucidio_6830 ,

 

The name of the field for Calculation2  in your form is spelled like this : "Calculation 2"  (with a blank space before the number 2), and not "Calculation2" (as expressed in your equations).

 

Field names in an equation must be spelled verbatim as they were created when you added the PDF objects to the form, otherwise just go ahead and adjust the field name in your equation to "Calculation 2" (instead of Calculation2).

 

The JavaScript console will keep throwing an error until this is fixed.

2 replies

Participating Frequently
December 2, 2025

 

You can pull the number from the previous calculation field instead of hardcoding it. For example, if the previous calculation is in a field named calculo2, replace 35 with its value:xcxcxcxcxcxcxcxcxcx.PNG

 

✅ Make sure calculo2 is calculated before this script runs, otherwise it will return 0 or NaN.

Bernd Alheit
Community Expert
Community Expert
November 23, 2025

Check the field calculation order.

November 23, 2025

I don't know if my friend understood. I didn't understand the order of the calculations. In the section below:

// Define o número de dias a ser adicionado
var diasParaAdicionar = Calculo2;

 

I wanted it to work with Calculation2 replacing the number 35.

try67
Community Expert
Community Expert
November 23, 2025

Use this:

var diasParaAdicionar = Number(this.getField("Calculo2").value);

You will still need to check the calculation order, though, to make sure that Calculo2 is calculated before this field. This is done outside of the code, though, under More - Set Fields Calculation Order in Prepare Form mode.