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

Create a JavaScript

New Here ,
Dec 12, 2016 Dec 12, 2016

Hello all -

I am hoping someone could help me create javascript for a personal reimbursement for that I have created for my office.

I would like for the employee id (six digit number) to auto populate in field B, when an employee enters their last name in field A. There is approx 50 or so employees in my office and I would like to capture all of them in these to fields.

Thank you in advance for you help.

TOPICS
Acrobat SDK and JavaScript , Windows
534
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

correct answers 1 Correct answer

Community Expert , Dec 12, 2016 Dec 12, 2016

The most simple way of doing it is with a series of statements like this (this code should be placed as the custom calculation script of the Employee ID field):

var employeeName = this.getField("Employee Name").valueAsString;

if (employeeName=="") event.value = "";

else if (employeeName=="John Doe") event.value = "123456";

else if (employeeName=="Jane Doe") event.value = "789000"; // etc.

Translate
Community Expert ,
Dec 12, 2016 Dec 12, 2016

There are a couple of ways it can be done. You can hard code the employee numbers and names into a script and then use a simple lookup or if-condition, or you can do it using an embedded text file that contains all of that data, and then when you need to update the list you just replace the text file with the new version and it will automatically update the lookup table. The latter is more complex, of course, and requires a custom-made script, but is much easier to maintain in the longer run.

For the former see this tutorial: https://acrobatusers.com/tutorials/change_another_field

If you're interested in hiring someone to develop the latter for you, feel free to contact me privately via try6767 at gmail.com.

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
New Here ,
Dec 12, 2016 Dec 12, 2016

I haven't done any scripts for a while now, but how would hard coding the employee numbers and names look like in a 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 ,
Dec 12, 2016 Dec 12, 2016

The most simple way of doing it is with a series of statements like this (this code should be placed as the custom calculation script of the Employee ID field):

var employeeName = this.getField("Employee Name").valueAsString;

if (employeeName=="") event.value = "";

else if (employeeName=="John Doe") event.value = "123456";

else if (employeeName=="Jane Doe") event.value = "789000"; // etc.

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
New Here ,
Dec 13, 2016 Dec 13, 2016
LATEST

Thank you Try67. Worked beautifully.

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