Copy link to clipboard
Copied
I have a page that has custom calculation scripts. I need that page duplicated an unknown amount of times. It could be once or fifty times. However when I duplicate it, the custom calculation scripts dont change when the forms are automatically renamed.
So the script attached to form A on original page, is the same script for form A on the duplicate page even though the page 2 form has a new name.
Is there a way to have the script automatically change with the new name of the form field?
Copy link to clipboard
Copied
Change the script such that it can handle the new names.
Copy link to clipboard
Copied
Assuming that you are spawning templates, you should use the bRename parameter as true, then handle the prefix in the field names.
Copy link to clipboard
Copied
This is the script I am using to generate the template page.
var t = this.getTemplate("RawTally");
t.spawn({nPage: this.numPages, bRename: true, bOverlay: false});
The fields are all renamed as new fields, so that part works.
However, the scripts in the calculations, didn't change from page to page. So the field on the new page has "P4" in front of everything except in the calculation script.
var v1 = getField("RawGross.0").value;
var v2 = getField("RawTare.0").value;
var v3 = getField("RawPalletWeight.0").value
event.value = v1 - v2 - v3;
If the script would have auto changed to the below, it would work.
var v1 = getField("P4.RawGross.0").value;
var v2 = getField("P4.RawTare.0").value;
var v3 = getField("P4.RawPalletWeight.0").value
event.value = v1 - v2 - v3;
Copy link to clipboard
Copied
You need to detect the P number and put it in a variable, for example :
var sPrefix = "P" + this.pageNum-1;
var v1 = getField(sPrefix + ".RawGross.0").value;
var v2 = getField(sPrefix + ".RawTare.0").value;
var v3 = getField(sPrefix + ".RawPalletWeight.0").value
event.value = v1 - v2 - v3;
Copy link to clipboard
Copied
Copy link to clipboard
Copied
To build the field names use the page number and the template name.
Copy link to clipboard
Copied
Bernd Alheit,
I do not understand how to do that.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Yeah I have still be unable to.
Copy link to clipboard
Copied
I am using the below script for my calculation script: //
var fieldName = event.target.name;
var suffix = fieldName.substring(fieldName.lastIndexOf(".") + 1);
var RawGrossA = getField("RawGrossA." + suffix);
var RawTareA = getField("RawTareA." + suffix);
var RawPalletWeightA = getField("RawPalletWeightA." + suffix);
var result = RawGrossA.value - RawTareA.value - RawPalletWeightA.value;
event.value = result;
I am using the below script for my button: //
var t = this.getTemplate("RawTally");
var XO = t.spawn(this.numPages, true, true);
The new forms on the new page are named P(n).RawTally.(Field Name).
This is a bit too complicated for myself. I can't get the custom calculation script to work on the new pages.
Copy link to clipboard
Copied
As said above, you must manage prefixes too.
Try this (not tested):
var fieldName = event.target.name.;
var aFieldName = fieldName.split(".");
var suffix = aFieldName.pop();
var prefix = aFieldName.shift();
prefix.slice(1);
var RawGrossA = getField("P" + prefix + ".RawGrossA." + suffix);
var RawTareA = getField("P" + prefix + ".RawTareA." + suffix);
var RawPalletWeightA = getField("P" + prefix + ".RawPalletWeightA." + suffix);
var result = RawGrossA.value - RawTareA.value - RawPalletWeightA.value;
event.value = result;
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more