Skip to main content
Participant
October 30, 2024
Question

Auto-populating a field based on another field

  • October 30, 2024
  • 1 reply
  • 692 views

Hello,

 

I am trying to have two fields get auto-populated (Tolerance/Weight Range and Readability/Capacity) based on another field (MFR./Model).

 

I've got a lot of data but to give an example, here's the first two:

 

MFR./Model = ACCULAB PP-2060D

Tolerance/Weight Range = 50 g ± 0.01 g

Readbaility/Capacity = 0.001g / 60g

 

MFR./Model = ACCULAB VIC-123

Tolerance/Weight Range = 100 g ± 0.010 g

Readbaility/Capacity = 0.001g / 120g

 

How should my custom validation script look like?

 

I'd appreciate your help. Thank you

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
October 30, 2024

Try this code:

 

if (event.value=="ACCULAB PP-2060D") {
	this.getField("Tolerance/Weight Range").value = "50 g ± 0.01 g";
	this.getField("Readbaility/Capacity").value = "0.001g / 60g";
} else if (event.value=="ACCULAB VIC-123") {
	this.getField("Tolerance/Weight Range").value = "100 g ± 0.010 g";
	this.getField("Readbaility/Capacity").value = "0.001g / 120g";
} // etc.
else {
	this.getField("Tolerance/Weight Range").value = "";
	this.getField("Readbaility/Capacity").value = "";
}
Participant
October 31, 2024

Hello,

I tried this inputting this

if (event.value=="ACCULAB PP-2060D") {
	this.getField("Tolerance/Weight Range").value = "50 g ± 0.01 g";
	this.getField("Readbaility/Capacity").value = "0.001g / 60g";
} else if (event.value=="ACCULAB VIC-123") {
	this.getField("Tolerance/Weight Range").value = "100 g ± 0.010 g";
	this.getField("Readbaility/Capacity").value = "0.001g / 120g";

 However, it's giving me this error:

 

SyntaxError: missing } in compound statement

6: at line 7 

 

I attached a screenshot of the error. Thank you

Bernd Alheit
Community Expert
Community Expert
November 5, 2024

Got it. Thank you.

 

Here's the code I tried and was able to enter but still didn't work.

 For the tolerance / weight range, here's what I have on my custom calculation script:

if (MFR/Model=="ACCULAB PP-2060D") {
this.getField("Tolerance").value = "50 g ± 0.01 g";
} else if (event.value=="ACCULAB VIC-123") {
this.getField("Tolerance").value = "100 g ± 0.010 g";}

 

For the readability/capacity, here's what I have on my custom calculation script:

if (MFR/Model=="ACCULAB PP-2060D") {
this.getField("Readability").value = "0.001g / 60g";
} else if (event.value=="ACCULAB VIC-123") {
this.getField("Readability").value = "0.001g / 120g";}

 

For the MFR/Model, I left the custom calculation script blank because this is what the first two depends on to be auto populated.

 

Am I thinking this incorrectly? What am I doing wrong 😕😕

 


Check the Javascript console for errors.