Skip to main content
Inspiring
February 29, 2024
Answered

Populating Company names based of of contract numbers

  • February 29, 2024
  • 1 reply
  • 6967 views

Can someone teach me what is wrong with this script? It says there's an unterminated string literal on line 3. When a user enters a contract number in Field1, I want the form to populate the name of the company the contract is tied to in the field this script is in.

 

var f = this.getField("Field1")

if(event.value == "Contract Number”)

f.value = "Company Name";

else
{
// do nothing
}

This topic has been closed for replies.
Correct answer try67

I want the user to only enter one contract number in Field1 so only one company name populates the field where we put this script.


Use this:

 

var f = this.getField("Field1")
if (event.value == "Contract Number1") {
	f.value = "Company Name1";
} else if (event.value == "Contract Number2") {
	f.value = "Company Name2";
} else {
	// do nothing
}

1 reply

try67
Community Expert
Community Expert
February 29, 2024

You must only use straight quotes, not curly ones, like at the end of this line:

if(event.value == "Contract Number)

Badhawg66Author
Inspiring
March 1, 2024

How would I populate the names of several companies using their contract number? Should I do something like this?

 

var f = this.getField("Field1")

if(event.value == "Contract Number1”)

f.value = "Company Name1";

var g = this.getField("Field1")

if(event.value == "Contract Number2”)

g.value = "Company Name2";

else
{
// do nothing
}

try67
Community Expert
Community Expert
March 1, 2024

Yes, but move the definition of the "g" variable to the top of the code.