Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Error transferring a number from one function to another.

Community Beginner ,
Nov 23, 2025 Nov 23, 2025
 
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?
 
TOPICS
PDF , PDF forms
909
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Nov 27, 2025 Nov 27, 2025

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.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 23, 2025 Nov 23, 2025

Check the field calculation order.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 23, 2025 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 23, 2025 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 26, 2025 Nov 26, 2025

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2025 Nov 26, 2025

Why have you changed the name of the variable?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2025 Nov 26, 2025

Share the file for further help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 27, 2025 Nov 27, 2025

Good morning
Attached is the requested file. I hope to receive help. The error persists in the DPP item, which cannot import the content of calculation 2.

Lucidio

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2025 Nov 27, 2025
var diasParaAdicionar = Number(this.getField("Calculo2").value);

This field doesn't exists in the form.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2025 Nov 27, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 27, 2025 Nov 27, 2025

It worked, friend. I fixed it and it worked. Thank you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 02, 2025 Dec 02, 2025

I still need to clarify a doubt regarding the difference between two dates on this same calculator. 

 

var date1 = this.getField("Date1").value;
var date1 = this.getField("Date2").value;

if (data1 && date1) {
// Converte as datas para objetos Date do JavaScript
var d2 = new Date(date2);
var d1 = new Date(data1);

// Calcula a diferença em milissegundos
var diff = d2.getTime() - d1.getTime();

// Converte milissegundos para dias (1000ms * 60s * 60m * 24h) e arredonda
var dias = Math.round(diff / (1000 * 60 * 60 * 24));

// Define o valor do campo atual (o campo calculado)
event.value = dias;
} else {
event.value = ""; // Limpa o campo se as datas não forem válidas
}

 

I used the script below, but it's not working. The difference would be today's date - the date of the exam.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 02, 2025 Dec 02, 2025

You use date1 for both dates. Check the JavaScript console for errors.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 02, 2025 Dec 02, 2025
LATEST

Also, the Date object constructor is not doing what you think it does... Run this code in the JS Console to see what's happening:

new Date("02/12/25")

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 02, 2025 Dec 02, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines