Depending on option selected non-relevant fields will be filled with black colour.

Community Beginner ,
Nov 18, 2020 Nov 18, 2020

Copy link to clipboard

Copied

Hi

I'd really appreciate if someone could help me.

I already have a script that will automatically fill non relevant fields a black colour when the user selects 'Contractor' from the drop down options. However I need other fields to be filled black if the user selects the other drop option 'Team Member' such as Manager Name and Job Title fields, etc.

Can I add something to the below script to include this?

var fields = ["Currency", "Salary", "Sal Basis", "Salary R", "Sal Year", "Per", "Per F", "Pro Day", "Pro Mont", "Note Day", "Note Mont", "Per", "Company Car", "Car Allowance", "Fuel Card", "Fuel Allowance", "PlanType", "LocalBonus", "Sub Plan", "Annual Target", "Target Amount", "Healthcare", "Local Healthcare", "Life Insurance", "Employee", "Employer", "Charged Segment",];
//
for (var i in fields) {
var f = this.getField(fields[i]);
if (event.value!="Contractor") {
f.required = true;
f.fillColor = color.transparent;
f.readonly = false;
} else {
f.required = false;
f.fillColor = color.black;
f.readonly = true;
}
}

TOPICS
Acrobat SDK and JavaScript, Create PDFs, How to, PDF forms

Views

104

Likes

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
Adobe Community Professional ,
Nov 18, 2020 Nov 18, 2020

Copy link to clipboard

Copied

May be possible with 2 arrays.

Likes

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 Beginner ,
Nov 18, 2020 Nov 18, 2020

Copy link to clipboard

Copied

Thanks Bernard, how would I apply 2 arrays?

Likes

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
Adobe Community Professional ,
Nov 18, 2020 Nov 18, 2020

Copy link to clipboard

Copied

Like this:

 

var fields1 = ...  // replace ... with the list of field names
var fields2 = ...

for (var i in fields1) {
  var f = this.getField(fields1[i]);
  f.required = true;
  f.fillColor = color.transparent;
  f.readonly = false;
}

for (var i in fields2) {
  var f = this.getField(fields2[i]);
  f.required = true;
  f.fillColor = color.transparent;
  f.readonly = false;
}

if (event.value=="Contractor") {
  for (var i in fields1) {
    var f = this.getField(fields1[i]);
    f.required = false;
    f.fillColor = color.black;
    f.readonly = true;
  }
} else if (event.value=="Team Member") {
  for (var i in fields2) {
    var f = this.getField(fields2[i]);
    f.required = false;
    f.fillColor = color.black;
    f.readonly = true;
  }
}

 

Likes

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 Beginner ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

Hi Bernard

 

I had to change the script to so that if the user selects Termination or Transfer then the non relevant fields will be filled with black. I followed you instructions but I seem to be missing something as its not working?

 

var fields1 = ...
var fields2 = ...

for (var i in fields1) {"Location","Department","Transfer Date","Payroll","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount","Owed To Employee","Deducted From Employee"
var f = this.getField(fields1[i]);
f.required = true;
f.fillColor = color.transparent;
f.readonly = false;
}

for (var i in fields2) {"Out Expenses","Exp Amount","Submitted To HR","Returned To HR","T&E DEPT","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount","Owed To Employee","Deducted From Employee"
var f = this.getField(fields2[i]);
f.required = true;
f.fillColor = color.transparent;
f.readonly = false;
}

if (event.value=="Termination") {
for (var i in fields1) {
var f = this.getField(fields1[i]);
f.required = false;
f.fillColor = color.black;
f.readonly = true;
}
} else if (event.value=="Transfer") {
for (var i in fields2) {
var f = this.getField(fields2[i]);
f.required = false;
f.fillColor = color.black;
f.readonly = true;
}
}

Likes

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
Adobe Community Professional ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

Check the Javascript console for errors.

Likes

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 Beginner ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

Normally when I enter a javascript with errors it will tell me instantly what they are but in this case it doesn't say anything?

Likes

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
Adobe Community Professional ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

You have not the values for the arrays fields1 and fields2.

Likes

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 Beginner ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

So at the beginning of the script do I enter the dropdown options as so

var fields1 = Termination
var fields2 = Transfer

 

Or am I suppose to enter the the list of fields I need to be be filled black when they select one of the options?

Likes

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
Adobe Community Professional ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

I mean the same way as in your first posting.

Likes

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 Beginner ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

I changed the script as follows and its now generating an error message 'SyntaxError: syntax error
1: at line 2'

var fields1 = ...["Location","Department","Transfer Date","Payroll","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount",
var fields2 = ...["Out Expenses","Exp Amount","Submitted To HR","Returned To HR","T&E DEPT","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount","Owed To Employee","Deducted From Employee",];

for (var i in fields1) {"Location","Department","Transfer Date","Payroll","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount","Owed To Employee","Deducted From Employee",];
var f = this.getField(fields1[i]);
f.required = true;
f.fillColor = color.transparent;
f.readonly = false;
}

for (var i in fields2) {"Out Expenses","Exp Amount","Submitted To HR","Returned To HR","T&E DEPT","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount","Owed To Employee","Deducted From Employee"
var f = this.getField(fields2[i]);
f.required = true;
f.fillColor = color.transparent;
f.readonly = false;
}

if (event.value=="Termination") {
for (var i in fields1) {
var f = this.getField(fields1[i]);
f.required = false;
f.fillColor = color.black;
f.readonly = true;
}
} else if (event.value=="Transfer") {
for (var i in fields2) {
var f = this.getField(fields2[i]);
f.required = false;
f.fillColor = color.black;
f.readonly = true;
}
}

Likes

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
Adobe Community Professional ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

Remove the points ...

Likes

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 Beginner ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

When I do that it says 'SyntaxError: syntax error 1: at line 2'

Likes

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
Adobe Community Professional ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

You must close a array with ] at the end.

Likes

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 Beginner ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

I inserted  ]; as per below but its still telling 'SyntaxError: syntax error 1: at line 2'

var fields1 = ...["Location","Department","Transfer Date","Payroll","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount",];

var fields2 = ["Out Expenses","Exp Amount","Submitted To HR","Returned To HR","T&E DEPT","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount","Owed To Employee","Deducted From Employee",];

for (var i in fields1) {"Location","Department","Transfer Date","Payroll","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount","Owed To Employee","Deducted From Employee",];
var f = this.getField(fields1[i]);
f.required = true;
f.fillColor = color.transparent;
f.readonly = false;
}

for (var i in fields2) {"Out Expenses","Exp Amount","Submitted To HR","Returned To HR","T&E DEPT","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount","Owed To Employee","Deducted From Employee"
var f = this.getField(fields2[i]);
f.required = true;
f.fillColor = color.transparent;
f.readonly = false;
}

if (event.value=="Termination") {
for (var i in fields1) {
var f = this.getField(fields1[i]);
f.required = false;
f.fillColor = color.black;
f.readonly = true;
}
} else if (event.value=="Transfer") {
for (var i in fields2) {
var f = this.getField(fields2[i]);
f.required = false;
f.fillColor = color.black;
f.readonly = true;
}
}

Likes

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
Adobe Community Professional ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

Once again: remove the 3 points.

Likes

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 Beginner ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

Sorry Bernard i've done that now and its showing a new error message 'SyntaxError: syntax error 1: at line 2'

var fields1 = ["Location","Department","Transfer Date","Payroll","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount",];

var fields2 = ["Out Expenses","Exp Amount","Submitted To HR","Returned To HR","T&E DEPT","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount","Owed To Employee","Deducted From Employee",];

for (var i in fields1) {"Location","Department","Transfer Date","Payroll","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount","Owed To Employee","Deducted From Employee",];
var f = this.getField(fields1[i]);
f.required = true;
f.fillColor = color.transparent;
f.readonly = false;
}

for (var i in fields2) {"Out Expenses","Exp Amount","Submitted To HR","Returned To HR","T&E DEPT","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount","Owed To Employee","Deducted From Employee"
var f = this.getField(fields2[i]);
f.required = true;
f.fillColor = color.transparent;
f.readonly = false;
}

if (event.value=="Termination") {
for (var i in fields1) {
var f = this.getField(fields1[i]);
f.required = false;
f.fillColor = color.black;
f.readonly = true;
}
} else if (event.value=="Transfer") {
for (var i in fields2) {
var f = this.getField(fields2[i]);
f.required = false;
f.fillColor = color.black;
f.readonly = true;
}
}

Likes

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
Adobe Community Professional ,
Nov 19, 2020 Nov 19, 2020

Copy link to clipboard

Copied

You've got a lot of non-sense in the for loops. Remove it.  Also, when posting code it needs to be formatted so we can read it. Please use indents, and do not run all the lines of code together. 

 

For example:

 

for (var i in fields1) 
{
    var f = this.getField(fields1[i]);
    f.required = true;
    f.fillColor = color.transparent;
    f.readonly = false;
}

 

This is the correct way to do it.  Notice the use of the code insertion tool. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

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 Beginner ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

Hi Thom

 

Thanks for getting in touch, that has helped remove the errors. The script now looks like the below. The problem I'm having now is that its not working, when I select the Termination or Transfer option nothing happens?

 

var fields1 = ["Location","Department","Transfer Date","Payroll","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount",];

var fields2 = ["Out Expenses","Exp Amount","Submitted To HR","Returned To HR","T&E DEPT","Fuel","Inform AWP","Bupa","Inform Com","Bike","Remaining Amount","Owner","Final Pay","Pay Direct","36 Months","Loan Amount","Owed To Employee","Deducted From Employee",];

for (var i in fields1)
{
    var f = this.getField(fields1[i]);
    f.required = true;
    f.fillColor = color.transparent;
    f.readonly = false;
}


for (var i in fields2)
{
    var f = this.getField(fields2[i]);
    f.required = true;
    f.fillColor = color.transparent;
    f.readonly = false;
}


if (event.value=="Termination") {
for (var i in fields1) {
var f = this.getField(fields1[i]);
f.required = false;
f.fillColor = color.black;
f.readonly = true;
}
} else if (event.value=="Transfer") {
for (var i in fields2) {
var f = this.getField(fields2[i]);
f.required = false;
f.fillColor = color.black;
f.readonly = true;
}
}

Likes

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
Adobe Community Professional ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

Where does you use the script? Any error message in the console?

Likes

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
Adobe Community Professional ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

LATEST

Yes, what Bernd asks. Where is this script being used? Is is validation script? Keystroke Script?

Are any errors reported?  Does the dropdown use export values for the items? Is the "commit immediately" option selected?

 

The first thing I would do is add this line of code to the top of the script:

 

console.println("Select:" + event.value);

 

Open the console window. When you make a selection, you should see the selected value displayed in the console. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

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