Combine 2 Javascripts Into 1
Hi guys
I need to combine the below 2 java scripts into 1. I would be most grateful if someone could advise if this is possible and if so how do I do it? I have marked the broken the scripts as **Script 1** and **Script 2**.
**Script 1**
//Start Script
//First you make the values for box1.
//var myPlanTypeValues = ["--SELECT--", "Leadership", "Mid-Management", "Sales"];
//Then you populate the values to box1.
//this.getField("PlanType").setItems(myPlanTypeValues);
// Then you define what has to be shown in box2 when value is selected
var accountingData = {
"Leadership": ["--SELECT--","MIB"],
"Mid-Management": ["--SELECT--","Local Bonus Plan"],
"Sales": ["--SELECT--","#1 Sales Account Manager – Aftermarket/Direct","#2 Sales Account Manager – OEM/Direct","#3 Sales Account Manager – OEM/Distribution","#4 Sales Account Manager – OEM/Overlay","#5 Sales Manager – Any Products","#6 Selling Sales Manager – Any Products","#7 New Business Developer – Aftermarket/Direct","#8 New Business Developer – OEM/Direct","#9 Sales Manager, New Business – Any Product","#10 Selling Sales Manager, New Business – Any Product","#11 Account Manager – Aftermarket/Direct","#12 Account Manager – OEM/Direct","#13 Account Manager – Aftermarket/Distribution","#14 Sales Manager, Existing Accounts – Any Product","#15 Account Service – Aftermarket/Direct","#16 Account Service – OEM/Direct","#17 Manager, Account Service – Any Product/Direct","#18 Growth Representative – Aftermarket/Distribution","Legacy Plan","TFS Sales VIC"],
"Shared Earnings/TM/Recognition": ["--SELECT--","Gainsharing Program","Local Bonus Plan","Materials Processing Incentive Bonus (MPIB)","Productivity Improvement Bonus (PIB)","Professional Incentive Bonus (PIB)", "Profit Sharing", "Recognition","SEP (Shared Earnings Plan)","SEP Plus","SSBP (Strategic Sourcing Bonus Plan)","Statutory Bonus Plan"],
};
//Finally you set the values of box2
function SetFieldValues(cDeptName){
this.getField("LocalBonus").setItems(accountingData[cDeptName]);
}
//Custom Keystroke PlanType
//if( event.willCommit ){
if(event.value == "--SELECT--"){
//app.alert(event.value)
//if nothing is chosen in box1 then box2 will be cleared
this.getField("Local Bonus").clearItems();
}else {
//app.alert(event.value)
SetFieldValues(event.value);
}
//
//ENDSCRIPT
//Finally you set the values of box2
function SetFieldValues(cDeptName){
this.getField("LocalBonus").setItems(accountingData[cDeptName]);
}
//Custom Keystroke PlanType
//if( event.willCommit ){
if(event.value == "--SELECT--"){
//app.alert(event.value)
//if nothing is chosen in box1 then box2 will be cleared
this.getField("LocalBonus").clearItems();
}else {
//app.alert(event.value)
SetFieldValues(event.value);
}
//}
//ENDSCRIPT
var accountingData = {
"Leadership": ["--SELECT--","MIB"],
"Mid-Management": ["--SELECT--","Local Bonus Plan"],
"Sales": ["--SELECT--","#1 Sales Account Manager – Aftermarket/Direct","#2 Sales Account Manager – OEM/Direct","#3 Sales Account Manager – OEM/Distribution","#4 Sales Account Manager – OEM/Overlay","#5 Sales Manager – Any Products","#6 Selling Sales Manager – Any Products","#7 New Business Developer – Aftermarket/Direct","#8 New Business Developer – OEM/Direct","#9 Sales Manager, New Business – Any Product","#10 Selling Sales Manager, New Business – Any Product","#11 Account Manager – Aftermarket/Direct","#12 Account Manager – OEM/Direct","#13 Account Manager – Aftermarket/Distribution","#14 Sales Manager, Existing Accounts – Any Product","#15 Account Service – Aftermarket/Direct","#16 Account Service – OEM/Direct","#17 Manager, Account Service – Any Product/Direct","#18 Growth Representative – Aftermarket/Distribution","Legacy Plan","TFS Sales VIC"],
"Shared Earnings/TM/Recognition": ["--SELECT--","Gainsharing Program","Local Bonus Plan","Materials Processing Incentive Bonus (MPIB)","Productivity Improvement Bonus (PIB)","Professional Incentive Bonus (PIB)","Profit Sharing","Recognition","SEP (Shared Earnings Plan)","SEP Plus","SSBP (Strategic Sourcing Bonus Plan)","Statutory Bonus Plan"],
};
//Finally you set the values of box2
function SetFieldValues(cDeptName){
this.getField("LocalBonus").setItems(accountingData[cDeptName]);
}
//Custom Keystroke Plan Type
//if( event.willCommit ){
if(event.value == "--SELECT--"){
//app.alert(event.value)
//if nothing is chosen in box1 then box2 will be cleared
this.getField("Local Bonus").clearItems();
}else {
//app.alert(event.value)
SetFieldValues(event.value);
}
//
//ENDSCRIPT
//Finally you set the values of box2
function SetFieldValues(cDeptName){
this.getField("Local Bonus").setItems(accountingData[cDeptName]);
}
//Custom Keystroke Plan Type
//if( event.willCommit ){
if(event.value == "--SELECT--"){
//app.alert(event.value)
//if nothing is chosen in box1 then box2 will be cleared
this.getField("Local Bonus").clearItems();
}else {
//app.alert(event.value)
SetFieldValues(event.value);
}
//}
//ENDSCRIPT
//Finally you set the values of box2
function SetFieldValues(cDeptName){
this.getField("LocalBonus").setItems(accountingData[cDeptName]);
}
//Custom Keystroke PlanType
//if( event.willCommit ){
if(event.value == "--SELECT--"){
//app.alert(event.value)
//if nothing is chosen in box1 then box2 will be cleared
this.getField("LocalBonus").clearItems();
}else {
//app.alert(event.value)
SetFieldValues(event.value);
}
//}
//ENDSCRIPT
**Script 2**
var fields = ["Sub Plan",];
//
for (var i in fields) {
var f = this.getField(fields);
if (event.value!="Professional Incentive Bonus (PIB)") {
f.required = true;
f.fillColor = color.transparent;
f.readonly = false;
} else {
f.required = false;
f.fillColor = color.black;
f.readonly = true;
}
}
