Skip to main content
raeben3
Inspiring
September 8, 2017
Answered

Why is simple field notation with subtraction not working?

  • September 8, 2017
  • 3 replies
  • 5571 views

I have set up a budget form and at the end I'm subtracting one manually entered field from another field with manually entered data.  This does nothing at all in Acrobat XI Pro. I got nothing, nada, no result.  In Acrobat DC Pro and DC Reader I get a result with like 8 decimal places (.00000000) and I can't see how to limit this to no decimal places. Now when I reopen in Acrobat XI, I am getting the same result as I got in DC, but only after a crash and restart of Acrobat.

I've even renamed the fields so they are super simple to enter... my equation "Barclay_Last-Barclay"

This should be a simple calculation -- have tried the "-" on above the keyboard and the "-" minus sign from the numpad. That makes no difference.  I have tried other calculations using *, for example, and they work fine.

Obviously something wrong here, but I don't think it's what I'm doing.  Is it because I have XI Pro and DC on the same Windows 7 machine?  Or ???

Correct answer Braptd

I may have a solution for you if you need to rename lots of field names.

My problem was a slightly different in that I wanted to change a field name with a "period" to an "underscore", since Adobe seems to struggle to do 'simplified field notation' calculations with fields that were named with a period, but not with an underscore.

so if i tried to do box.1 - box.2, nothing happened, but when renamed to box_1 and box_2, now the formula box_1 - box_2 in 'simplified field notation' works fine.

For some reason when you create multiple text boxes (such as when you right click on one field and then do 'create multiple copies..') it renames each one with a period, so if your first field is named "box", and you create 2 copies, it will rename them "box.1" and "box.2".

On windows, ctrl+J to open the javascript console, clear the console and paste this into the console, (the box one at the bottom). Do ctrl+A to select all of the script that you just pasted, and then ctrl+enter to execute it. It should rename the fields to "box_1" and "box_2" and so on.  Hope this can help someone.

Script:
// Loop backwards so that removal doesn't affect the loop indices
for (var i = this.numFields - 1; i >= 0; i--) {
var origName = this.getNthFieldName(i);
if (origName.indexOf('.') !== -1) {
var newName = origName.replace(/\./g, '_'); // Replace all periods with underscores

// Get the original field
var origField = this.getField(origName);
if (!origField) continue; // safety check

// Create a new field with the same type, page, and rectangle
// Note: You may need to adjust parameters depending on your field type.
var newField = this.addField(newName, origField.type, origField.page, origField.rect);

// Copy basic properties. You may want to copy additional properties as needed.
newField.value = origField.value;
newField.defaultValue = origField.defaultValue;
newField.textSize = origField.textSize;
newField.multiline = origField.multiline;
newField.alignment = origField.alignment;
newField.readonly = origField.readonly;

// Copy any additional properties if needed:
// newField.font = origField.font; etc.

// Remove the original field
this.removeField(origName);

console.println("Renamed field '" + origName + "' to '" + newName + "'");
}
}

3 replies

BraptdCorrect answer
Participating Frequently
February 4, 2025

I may have a solution for you if you need to rename lots of field names.

My problem was a slightly different in that I wanted to change a field name with a "period" to an "underscore", since Adobe seems to struggle to do 'simplified field notation' calculations with fields that were named with a period, but not with an underscore.

so if i tried to do box.1 - box.2, nothing happened, but when renamed to box_1 and box_2, now the formula box_1 - box_2 in 'simplified field notation' works fine.

For some reason when you create multiple text boxes (such as when you right click on one field and then do 'create multiple copies..') it renames each one with a period, so if your first field is named "box", and you create 2 copies, it will rename them "box.1" and "box.2".

On windows, ctrl+J to open the javascript console, clear the console and paste this into the console, (the box one at the bottom). Do ctrl+A to select all of the script that you just pasted, and then ctrl+enter to execute it. It should rename the fields to "box_1" and "box_2" and so on.  Hope this can help someone.

Script:
// Loop backwards so that removal doesn't affect the loop indices
for (var i = this.numFields - 1; i >= 0; i--) {
var origName = this.getNthFieldName(i);
if (origName.indexOf('.') !== -1) {
var newName = origName.replace(/\./g, '_'); // Replace all periods with underscores

// Get the original field
var origField = this.getField(origName);
if (!origField) continue; // safety check

// Create a new field with the same type, page, and rectangle
// Note: You may need to adjust parameters depending on your field type.
var newField = this.addField(newName, origField.type, origField.page, origField.rect);

// Copy basic properties. You may want to copy additional properties as needed.
newField.value = origField.value;
newField.defaultValue = origField.defaultValue;
newField.textSize = origField.textSize;
newField.multiline = origField.multiline;
newField.alignment = origField.alignment;
newField.readonly = origField.readonly;

// Copy any additional properties if needed:
// newField.font = origField.font; etc.

// Remove the original field
this.removeField(origName);

console.println("Renamed field '" + origName + "' to '" + newName + "'");
}
}

S_S
Community Manager
Community Manager
March 10, 2025

Hi @Braptd,

 

Hope you are doing well. 

 

Thanks for writing about what worked for you.

Marking this as a correct answer for future users to use as reference.


Regards,
Souvik.

Inspiring
September 10, 2017

You should be able to control the displayed number of decimal places using the format tab and setting the format to "Number" and the number of decimal places to ")". Note this will round the result of the calculation.

You may need to have a space before and after the minus sign. Simplified field notation uses spaces to parse the entry into field names, values and operands. The "-" can indicate subtraction or a negative value. The space after the "-" indicated one wants to subtract the value and not have it as a negative value.

raeben3
raeben3Author
Inspiring
September 11, 2017

Thanks, 

I should have been able to figure out the decimal place.  Geez. Sometimes the brain is just not helping. 

I have included a space before and after but still my Simple Notation calculation is not working. 

Here is what I have written:

Text4.0.6.0 - Barclay

Tried formatting those fields as numerical, that did not help. 

Inspiring
September 11, 2017

The "." is a special character and denotes a decimal place in a numeric value. It needs to be "Escaped" to indicate to the behind the scenes JavaScript that the "." is to be treated as a character and not a decimal point. Try:

Text4\.0\.6\.0 - Barclay

Inspiring
September 9, 2017

Does it not work for all entered values or just certain ones? If just certain ones, can you give some examples?

raeben3
raeben3Author
Inspiring
September 11, 2017

Thanks for your interest.  My simple notation formula is this

Text4.0.6.0 - Barclay

Tried formatting all 3 fields (the calculation field, Barclay and Text4.0.6.0) as numerical, that did not help.  All data in these fields is positive, not negative.  These are the only Simple Notation calculations I'm using and none of them work.  Other calculations where value is Sum, work. 

Inspiring
September 11, 2017

That's a different field name than you showed before. If you have punctuation like that in the field name, you'll have to escape the characters like this:

Text4\.0\.6\.0 - Barclay

It's best to use only alphanumeric characters (plus underscore) for field names so you don't have to bother with this.