Skip to main content
Participating Frequently
August 1, 2018
Question

Why does my Acrobat X Pro debugger complain this script?

  • August 1, 2018
  • 2 replies
  • 1289 views

My Javascript code for calculating a value from a specific date difference the debugger complains with no understandable reasons.

E.g. "GetFullYear is not a function" although These are normal Javascript functions.

This is the code:

var PastDate = this.getField("Datum1").value;

var jetzt = new Date();

PastDate = PastDate.split(".");

var DateDiff = jetzt.GetFullYear()-PastDate[2] + 12*(jetzt.GetMonth() - PastDate[1]);

this.getField("€_2").value = DateDiff / 12 * this.getField("Prozent1").value / 100 * this.getField("€").value;

Could anybody inform me please what is wrong at the script and where I can find a suiting documentation to easily build such scripts?

Cause the Adobe Javasript API Acrobat DC SDK Documentation  does not really help.

Thank you very much.

This topic has been closed for replies.

2 replies

Inspiring
August 1, 2018

Just a tip: If you're going to be using a field value as a string (e.g., by using string methods with it), you should get the field value using the valueAsString property, as opposed to the value property. It's just a good habit to get into.

try67
Community Expert
Community Expert
August 1, 2018

Another tip to all script writers out there: If you want to use the value of a field in a calculation, always convert it explicitly into a number, by using the Number object constructor. For example:

Number(this.getField("FieldName").valueAsString)

This is especially important if you add values, as the "+" operator has a double function: When used for numbers it adds them up, as expected, but when used for strings it concatenates them, so if either one of the values added is actually a string, the result will be a concatenated string. For example:

1 + 1 = 2

1 + "1" = "11"

"1" + 1 = "11"

"1" + "1" = "11"

Participating Frequently
August 1, 2018

Thank you again!

Actually I had this kind of problem at last but your tipp didn't help.

This was my code:

var startDate = Number(this.getField("Datum1").valueAsString);     // 01.08.2017

var endDate = Number(this.getField("Datum1b").valueAsString);     // 08.04.2018

startDate = startDate.split(".");    

endDate = endDate.split(".");

var DateDiff = 12*(endDate[2]-startDate[2]) + endDate[1]-startDate[1];     // =1096

In fact you had to put the last substraction into brackets to get the right result 8!!

var startDate = this.getField("Datum1").valueAsString;                    // 01.08.2017

var endDate = this.getField("Datum1b").valueAsString;                   // 08.04.2018

startDate = startDate.split(".");

endDate = endDate.split(".");

var DateDiff = 12*(endDate[2]-startDate[2]) + (endDate[1]-startDate[1]);     // =8

JR Boulay
Community Expert
Community Expert
August 1, 2018

GetFullYear is not the same than getFullYear.

JavaScript is case sensitive.

You will have the same issue with GetMonth, etc.

Acrobate du PDF, InDesigner et Photoshopographe
Participating Frequently
August 1, 2018

Oh yes, thank you VERY much.

I was not aware of that.

The debugger also complained the split function. So I assumed that the problem is much bigger.

But now this works fine as well.

Thank you again!!