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;
}
}
Copy link to clipboard
Copied
May be possible with 2 arrays.
Copy link to clipboard
Copied
Thanks Bernard, how would I apply 2 arrays?
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;
}
}
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;
}
}
Copy link to clipboard
Copied
Check the Javascript console for errors.
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?
Copy link to clipboard
Copied
You have not the values for the arrays fields1 and fields2.
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?
Copy link to clipboard
Copied
I mean the same way as in your first posting.
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;
}
}
Copy link to clipboard
Copied
Remove the points ...
Copy link to clipboard
Copied
When I do that it says 'SyntaxError: syntax error 1: at line 2'
Copy link to clipboard
Copied
You must close a array with ] at the end.
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;
}
}
Copy link to clipboard
Copied
Once again: remove the 3 points.
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;
}
}
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.
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;
}
}
Copy link to clipboard
Copied
Where does you use the script? Any error message in the console?
Copy link to clipboard
Copied
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.