Highlighted

How can I solve the problem "The value entered does not match the format of the field".

New Here ,
Sep 08, 2020

Copy link to clipboard

Copied

Hello everybody.

 

This is my first time working in Adobe with Java Script.

 

I have created a document in which a certain percentage should be deducted from a value.

 

If all values are subtracted correctly the result should be 0. The formula works fine for some numbers.

With other numbers (for example: 3,6,7,12,14,17,19) the error "The value entered does not match the format of the field" occurs.
 
This is the script I use. Unfortunately I cannot explain the errors at all.

var v1 =

this.getField("Reisetage").value;
var v2 =
this.getField("k-an").value;
var v3 =
this.getField("f-an").value;
var v4 =
this.getField("m-an").value;
var v5 =
this.getField("a-an").value;


var v6 = 0;

if(v1=="ein"){
v6 = 0;
}

if(v1=="mehr"){
v6 = v2 - (v3*20/100*v2)
-(v4*40/100*v2)
-(v5*40/100*v2);
}

this.getField("Anreise").value = v6;

 
Perhaps someone can help me with this problem.
TOPICS
Acrobat SDK and JavaScript, Create PDFs

Views

39

Likes

Translate

Translate

Report

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

How can I solve the problem "The value entered does not match the format of the field".

New Here ,
Sep 08, 2020

Copy link to clipboard

Copied

Hello everybody.

 

This is my first time working in Adobe with Java Script.

 

I have created a document in which a certain percentage should be deducted from a value.

 

If all values are subtracted correctly the result should be 0. The formula works fine for some numbers.

With other numbers (for example: 3,6,7,12,14,17,19) the error "The value entered does not match the format of the field" occurs.
 
This is the script I use. Unfortunately I cannot explain the errors at all.

var v1 =

this.getField("Reisetage").value;
var v2 =
this.getField("k-an").value;
var v3 =
this.getField("f-an").value;
var v4 =
this.getField("m-an").value;
var v5 =
this.getField("a-an").value;


var v6 = 0;

if(v1=="ein"){
v6 = 0;
}

if(v1=="mehr"){
v6 = v2 - (v3*20/100*v2)
-(v4*40/100*v2)
-(v5*40/100*v2);
}

this.getField("Anreise").value = v6;

 
Perhaps someone can help me with this problem.
TOPICS
Acrobat SDK and JavaScript, Create PDFs

Views

40

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 08, 2020 0
Adobe Community Professional ,
Sep 08, 2020

Copy link to clipboard

Copied

HI,

 

Would you be able to share the document that shows the problem, as that would make it easier for us to get to the cause?

 

Regards

 

Malcolm

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 08, 2020 0
New Here ,
Sep 08, 2020

Copy link to clipboard

Copied

I have adapted the file.
Maybe there will be some difficulties in understanding the file because it is in German.

The problem arises in the calculations under "Mehrtägige Reise".

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 08, 2020 0
Adobe Community Professional ,
Sep 08, 2020

Copy link to clipboard

Copied

What does you get when you change the format of the field to "None" ?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 08, 2020 0
New Here ,
Sep 08, 2020

Copy link to clipboard

Copied

If you change the format to none, the programme will execute the calculation incorrectly.

I have attached the file.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 08, 2020 0
Adobe Community Professional ,
Sep 08, 2020

Copy link to clipboard

Copied

Hi, It looks like you have hit one of the quirks of JavaScript and Maths, so when I use the value 3 for all entries, then the Tage field is trying to be set to '8.881784197001252e-16' which is a really small number, and for some reason doesn't get rounded when you apply the formatting to it. If you change your script a little so that the last line is something like: this.getField("Tage").value = util.printf("%.2f", +v7); Then the formatting error is removed. Hope this helps. Malcolm

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 08, 2020 0
New Here ,
Sep 08, 2020

Copy link to clipboard

Copied

Hello, Malcolm,
actually it worked with the modified script. Thanks a lot, I'm already desperate about it.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 08, 2020 0
try67 LATEST
Most Valuable Participant ,
Sep 08, 2020

Copy link to clipboard

Copied

This almost always happens when you have a field set as having a Number format and a calculation script that uses division by the value of another field. When that field is empty or zero that results in Infinity (since division by zero is not allowed), which the Number format can't handle. The solution is to add a condition to the code to check that all divisors are not zero before applying the calculation. In your case that would be the value of v2, ie. the "k-an" field.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 08, 2020 0