Copy link to clipboard
Copied
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
}
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
}
Copy link to clipboard
Copied
You must only use straight quotes, not curly ones, like at the end of this line:
if(event.value == "Contract Number”)
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
Yes, but move the definition of the "g" variable to the top of the code.
Copy link to clipboard
Copied
Like this?
var f = this.getField("Field1")
var g = this.getField("Field1")
if(event.value == "Contract Number1”)
f.value = "Company Name1";
if(event.value == "Contract Number2”)
g.value = "Company Name2";
else
{
// do nothing
}
Copy link to clipboard
Copied
Wait, do you have one field, or two? If the latter, you need to adjust the field name in the definition of the "g" variable...
Copy link to clipboard
Copied
I only have one field. What do I need to do in this case?
Copy link to clipboard
Copied
Then I don't follow... Do you want to populate it with two company names one after another? In different lines (if it's a multiline field)? In the same line?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
I didn't have any luck with that. Just so you know, I have 9 other contract numbers and company names I need to put in there.
Copy link to clipboard
Copied
Did you adjust the code to reflect your actual field names and values?
Copy link to clipboard
Copied
Yes I did.
Copy link to clipboard
Copied
Can you share the file?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I don't see the code anywhere...
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Works fine for me... But you should move the code to the custom Validation script if you want it to not throw errors when you change the value of the Row Contract No. field manually.
Copy link to clipboard
Copied
I put the code in the Validation script but when I enter the contract number it doesn't populate a company name. Do you think that has something to do with using the older version of adobe?
Copy link to clipboard
Copied
No, but you have to make sure you enter it exactly as it appears in the code.
Also, the other field won't update until you leave the first field, as that's when the value is applied and the script is executed.
Copy link to clipboard
Copied
I cut everything from the calculation script and pasted it in the validation script
I copied a contract number from the validation script and clicked out but it didn't populate
When I clicked the field it does nothing
I put this code in the validation script but it didn't work
var a = this.getField("ROW Contract No")
var b = this.getField("ROW Contract No")
var c = this.getField("ROW Contract No")
var d = this.getField("ROW Contract No")
var e = this.getField("ROW Contract No")
var f = this.getField("ROW Contract No")
var g = this.getField("ROW Contract No")
var h = this.getField("ROW Contract No")
var l = this.getField("ROW Contract No")
var j = this.getField("ROW Contract No")
var k = this.getField("ROW Contract No")
if(event.value == "RW-2368A")
a.value = "AG3 GROUP";
if(event.value == "RW-2368B")
b.value = "ATKINS GLOBAL, INC";
if(event.value == "RW-2368C")
c.value = "BENCHMARK, LLC";
if(event.value == "RW-2368D")
d.value = "BENHAM DESIGN, LLC";
if(event.value == "RW-2368E")
e.value = "EST, INC";
if(event.value == "RW-2368F")
f.value = "HUDSON & PRINCE, PLLC";
if(event.value == "RW-2368G")
g.value = "KIETHLINE ENGINEERING, LLC";
if(event.value == "RW-2368H")
h.value = "LEADS, LLC";
if(event.value == "RW-2368L")
l.value = "TEIM DESIGN, PLLC";
if(event.value == "RW-2368J")
j.value = "POE & ASSOCIATES, INC";
if(event.value == "RW-2368K")
k.value = "REDFIRE ENGINEERING, LLC";
else
{
// do nothing
I'm not sure what to do 😅
Copy link to clipboard
Copied
There's no need to define a separate variable for each condition. One is enough.
But it looks like the field you're placing the code under is "ROW Contract No"... It should be the other way around. Or you should change your code to point to the text field you want to populate.
Copy link to clipboard
Copied
Nothing was in the "ROW Contract No" field. The code is in the "Submitted By_2" field. I'm not sure how the "UT Proj No" field was selected when I was editing the code.
Copy link to clipboard
Copied
Could you please attach the file that worked for you?
Copy link to clipboard
Copied