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

Populating Company names based of of contract numbers

Explorer ,
Feb 29, 2024 Feb 29, 2024

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
}

TOPICS
JavaScript , PDF , PDF forms

Views

3.0K

Translate

Translate

Report

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

correct answers 1 Correct answer

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
}

Votes

Translate

Translate
Community Expert ,
Feb 29, 2024 Feb 29, 2024

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)

Votes

Translate

Translate

Report

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

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
}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

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
}

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

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?

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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
}

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Yes I did.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Can you share the file?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

I don't see the code anywhere...

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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?

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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 😅

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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.

Badhawg66_0-1709570178227.png

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Could you please attach the file that worked for you?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Here you go...

Votes

Translate

Translate

Report

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