Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

tickbox weight automation

New Here ,
Jun 04, 2025 Jun 04, 2025

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.

charlie_7591_0-1749023044306.png

 

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.

TOPICS
How to , JavaScript , PDF , PDF forms
517
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Jun 04, 2025 Jun 04, 2025

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;
}

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 05, 2025 Jun 05, 2025

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);

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 04, 2025 Jun 04, 2025

Do you use script to fill those two fields, if yes what is it?
What is the name of the checkbox and weight fields?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 04, 2025 Jun 04, 2025

i dont use a script. i just use the sum + then select all of the weight fields i want to calculate.

 

charlie_7591_0-1749041376602.pngcharlie_7591_1-1749041389750.png

also these are the names of all the fields you should need. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 04, 2025 Jun 04, 2025

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 04, 2025 Jun 04, 2025

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

charlie_7591_0-1749048145068.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 04, 2025 Jun 04, 2025

What should happen if both boxes are ticked?

And what are the names of the fields involved?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 04, 2025 Jun 04, 2025

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.

charlie_7591_1-1749036401484.png

 

if the box tickbox is ticked i would like the box net weight only to be calculated 

charlie_7591_2-1749036472656.png

 

if box tick boxes are ticked i would like both net weights to be calculated by weight like this 

charlie_7591_3-1749036533148.png

 

hopefully this makes sense and you can guage what i am trying to do here haha. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 04, 2025 Jun 04, 2025

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;
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 04, 2025 Jun 04, 2025

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 05, 2025 Jun 05, 2025

Can you share the file?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 05, 2025 Jun 05, 2025

sure. here you go i attatched the file. thanks for the help i really appreciate it. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 05, 2025 Jun 05, 2025

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);

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 05, 2025 Jun 05, 2025

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 05, 2025 Jun 05, 2025

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 05, 2025 Jun 05, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 10, 2025 Jun 10, 2025

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 10, 2025 Jun 10, 2025
LATEST

Sure. What is the formula to calculate it?

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