Copy link to clipboard
Copied
ive got a document with automated weight fields. So when the net weight gets filled at the bottom it adds it to the top two net weights as shown by the arrows.
what i am trying to do is code so that if the pallete tickbox is ticked it only fills in the left hand net weight with the net weight.
if the box is instead ticked it only fills out the net weight in the right hand net weight. as currently it fills in box left and right hand net weights.
hopefully this makes sense. if not feel free to ask me any questions id be happy to answer them.
Copy link to clipboard
Copied
This is a bit tricky since the names of the fields you want to add are not consistent, but you can use something like this as the custom calculation script of the first field:
if (this.getField("Check Box1.1").valueAsString=="Off") event.value = "";
else {
var total = 0;
total+=Number(this.getField("Weight1").valueAsString);
total+=Number(this.getField("Weight2").valueAsString);
total+=Number(this.getField("Weight3").valueAsString);
total+=Number(this.getField("Weight4").valueAsString);
// etc.
event.value = total;
}
Copy link to clipboard
Copied
You placed the code in the wrong location. It needs to go under the Calculate event of the Net Weight field, replacing what you currently have there. Also, you need to duplicate (and modify the field name in it) this line for each of the fields you want to add up:
total+=Number(this.getField("Weight1").valueAsString);
Copy link to clipboard
Copied
Do you use script to fill those two fields, if yes what is it?
What is the name of the checkbox and weight fields?
Copy link to clipboard
Copied
i dont use a script. i just use the sum + then select all of the weight fields i want to calculate.
also these are the names of all the fields you should need.
Copy link to clipboard
Copied
The field names are not fully visible. Please post them as text. Also, I thought the fields were just supposed to show the value of a single field, but in the screenshot it appears to be the sum of multiple ones...
Copy link to clipboard
Copied
Check Box1.1, Dropdown3.1.1, Check Box1.0, Dropdown3.1.0 although these dont matter and can be changed.
plus all of the net weight fields that go down to the bottom of the page automate and are the sum of the net weight at the top. its like the overal net weight if you will of all the other net weights that go down to the bottom of the page if that makes sense
Copy link to clipboard
Copied
What should happen if both boxes are ticked?
And what are the names of the fields involved?
Copy link to clipboard
Copied
i would like if both boxes are ticked then both net weights to be filled in. if one tickbox is ticked i only want one net weights to be filled in. if that makes sense?
so if the pallete tick box is ticked i would like the pallete net weight to be calculated.
if the box tickbox is ticked i would like the box net weight only to be calculated
if box tick boxes are ticked i would like both net weights to be calculated by weight like this
hopefully this makes sense and you can guage what i am trying to do here haha.
Copy link to clipboard
Copied
This is a bit tricky since the names of the fields you want to add are not consistent, but you can use something like this as the custom calculation script of the first field:
if (this.getField("Check Box1.1").valueAsString=="Off") event.value = "";
else {
var total = 0;
total+=Number(this.getField("Weight1").valueAsString);
total+=Number(this.getField("Weight2").valueAsString);
total+=Number(this.getField("Weight3").valueAsString);
total+=Number(this.getField("Weight4").valueAsString);
// etc.
event.value = total;
}
Copy link to clipboard
Copied
i added your code to the tickboc with the run a javascript action. it does not appear to do anything different. when i tick or untick the tick box it still shows the weights in the overal net weight left hand side.
Copy link to clipboard
Copied
Can you share the file?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You placed the code in the wrong location. It needs to go under the Calculate event of the Net Weight field, replacing what you currently have there. Also, you need to duplicate (and modify the field name in it) this line for each of the fields you want to add up:
total+=Number(this.getField("Weight1").valueAsString);
Copy link to clipboard
Copied
it works perfectly actually. you are right i just had it pasted in the wrong location. thank you so much for the help you truly are a genius. i couldnt of done it without you.
Copy link to clipboard
Copied
Could you inspect the document one last time. It was working with the 4 lines of code you given me. I have filled in all of the rest of the lines of all the weight fields. also changed the name of the text box to match. but now it does not seem to be working. I must have done something wrong to the code.
Copy link to clipboard
Copied
One of the field names you specified is incorrect. Open the JS Console (Ctrl+J) and it will show you the line number where the error happened. Go to that line and look for the misspelled field. It could be on the line before or after it, though. Remember it has to match EXACTLY, including spaces, upper-/lower-case letters, etc.
Copy link to clipboard
Copied
if i wanted to expand on your code you given me for the net weight. Would it be possible to automate the gross weight from the net weight code? please and thank you
Copy link to clipboard
Copied
Sure. What is the formula to calculate it?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now