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

Populating Company names based of of contract numbers

Explorer ,
Feb 29, 2024 Feb 29, 2024

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
}

TOPICS
JavaScript , PDF , PDF forms
4.6K
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
1 ACCEPTED SOLUTION
Community Expert ,
Mar 01, 2024 Mar 01, 2024

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
}

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 ,
Feb 29, 2024 Feb 29, 2024

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

if(event.value == "Contract Number)

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
Explorer ,
Mar 01, 2024 Mar 01, 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
}

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 ,
Mar 01, 2024 Mar 01, 2024

Yes, but move the definition of the "g" variable to the top of 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
Explorer ,
Mar 01, 2024 Mar 01, 2024

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
}

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 ,
Mar 01, 2024 Mar 01, 2024

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

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
Explorer ,
Mar 01, 2024 Mar 01, 2024

I only have one field. What do I need to do in this case?

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 ,
Mar 01, 2024 Mar 01, 2024

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?

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
Explorer ,
Mar 01, 2024 Mar 01, 2024

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.

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 ,
Mar 01, 2024 Mar 01, 2024

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
}
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
Explorer ,
Mar 01, 2024 Mar 01, 2024

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.

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 ,
Mar 01, 2024 Mar 01, 2024

Did you adjust the code to reflect your actual field names and values?

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
Explorer ,
Mar 01, 2024 Mar 01, 2024

Yes I did.

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 ,
Mar 01, 2024 Mar 01, 2024

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
Explorer ,
Mar 01, 2024 Mar 01, 2024

Yes I can, here it is. The contract number in "ROW Contract No" needs to populate a company's name in "Submitted By_2". Once I figure out how to populate the company's name, I should be able to use it to populate company's address and phone number

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 ,
Mar 01, 2024 Mar 01, 2024

I don't see the code anywhere...

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
Explorer ,
Mar 01, 2024 Mar 01, 2024

Sorry, I forgot to save it with the code. The code is in the "Submitted By_2" field in this attachment.

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 ,
Mar 01, 2024 Mar 01, 2024

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.

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
Explorer ,
Mar 01, 2024 Mar 01, 2024

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?

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 ,
Mar 01, 2024 Mar 01, 2024

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.

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
Explorer ,
Mar 04, 2024 Mar 04, 2024

I cut everything from the calculation script and pasted it in the validation script

Badhawg66_0-1709563254944.png 

I copied a contract number from the validation script and clicked out but it didn't populate

Badhawg66_1-1709563306409.png

When I clicked the field it does nothing

Badhawg66_2-1709563575360.png

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 😅

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 ,
Mar 04, 2024 Mar 04, 2024

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.

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
Explorer ,
Mar 04, 2024 Mar 04, 2024

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.

Badhawg66_0-1709570178227.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
Explorer ,
Mar 06, 2024 Mar 06, 2024

Could you please attach the file that worked for 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 ,
Mar 06, 2024 Mar 06, 2024

Here you go...

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