I have a PDF I'm putting together that is a product list with multiple rows, across multiple pages. It calculates Price x Order Quantity and gives a total in the last box. Example attached. Yes, I'm aware my version of Acrobat is getting very old
Is there a way to use the "create multiple copies" function but have the calculation update to match the new field name. As it is, the "cost" field wants to use the calculation from the first row and doesn't auto-update.
Hope that makes sense, cheers.
The answer is most likely yes, but it depends on your particular setup. The general solution is to create a folder level function that generates the field names that it needs based on the name of the current cost field. For this technique to work, all the fields on the same row have to follow the same naming convention. This function is called from the cost field, so the name of the current cost field is in "event.targetName", All it should take is some text operations to generate the names of the other fields on the same row.
Here's a short article on the topic:
Yes, it is possible. Here's how you do it:
Create your first row of fields with the basic names you want to use, WITHOUT any numbers at the end. For example, "Qty", "Price" and "Cost".
If you duplicate them (don't do it yet!) the new fields names will be "Qty.0", "Qty.1", etc., "Price.0", "Price.1", etc., and "Cost.0", "Cost.1", etc.
So the field names are consistent, which means we can write a script that will work in any row.
So now we go back to the original Cost field and use the following code as its custom calculation script:
var baseName = "Cost";
var qtyFieldName = event.target.name.replace(baseName, "Qty");
var priceFieldName = event.target.name.replace(baseName, "Price");
var qtyField = this.getField(qtyFieldName);
var priceField = this.getField(priceFieldName)
event.value = Number(qtyField.valueAsString) * Number(priceField.valueAsString);
If you do that first and then duplicate the fields you'll see that the code continues to work for each row on its own.
Thank you so much! I'll try this out tomorrow. I was looking at having to manually set the calculation for each row, over many many rows, on multiple pages - you're an absolute life saver mate, really appreciate it.