Script for dependent and autopopulated fields

Hi

I would really appreciate if someone could help me.

I’m trying to write a javascript for 3 fields. The first will have drop down options, the second field will have drop down options based on the first field. The final field will automatically populate based on the what has been selected in the previous 2 fields.

I have the script written below but its bringing up errors which I don’t know how to fix.

Can someone please help me?
var adpData = {
Genie: ["",“I30000”,“I30101”,“I30400”,“I30401”,“I30404”,“I30501”,“I30505”,“I30601”,“I30602-PSR”,“I30703”,“I51003 - PSR”,“I70000”,“I70199”,“I80000”,“I80101”,“I90201”,“I90299”]
Pegson: ["",“60109”, “70000”,“60901”,“61202”,“30602”,“60106”,“90000”,“90301”,“30703”,“30501”,“30401”,“30102”,”30101”,”60204”,”60401/60210”,”60202”]
Cranes UK: ["",“D60401”,“I80106”,“I30000”,“I80105”,“I90201”,“I95103”]
};
var accountData = {
I30000: [“(302)Recharge - TFSE”],
I30101: [“(310)Recharge - Terex USA"],
I30400: [“(293)HR”],
I30401: [“(304)Recharge - Terex Corp”],
I30404: [“(241)Training”],
I30501: [“(292)IT”],
I30505: [“(284)TMS”],
I30601: [“(306)Recharge”],
I30602-PSR: [“(272)Used Equipment”],
I30703: [“(200)Finance”],
I51003 – PSR: [“(240)Service”],
I70000: [“(240)Service”],
I70199: [“(272)Used Equipment”],
I80000: [“(220)Parts”],
I80101: [“(210)Inventory”],
I90201: [“(260)Sales”],
I90299: [“(261)Marketing”],
60109: [“(10-11)Production support General - Indirect”],
70000: [“(10-13)Crusher Design”],
60901: [“(10-15)Quality & Reliability - Indirect”],
61202: [“(10-16)Stores - Indirect”],
30602: [“(10-17)Maintenance - Indirect”],
60106: [“(10-25)Production Planning”],
90000: [“(10-40)Quarry Sales”],
90301: [“(10-47)Strategic Marketing”],
30703: [“(10-70)Accounts Department”],
30501: [“(10-72)IT”],
30401: [“(10-74)HR”],
30102: [“(10-75)MD’s Office”],
30101: [“(10-81)Fabrication - Direct”],
60204: [“(10-85)Quarry Plant Ass. Shop Bay 4 - Direct”],
60401/60210: [“(10-86)Quarry Machine Fitting Shop Bay 3 - Direct”],
60202: [“(10-89)Bay 2 Machine Shop - Direct”],
D60401: [“Machine Shop 1”],
I80106: [“Distr – Service”],
I30000: [“Business Support”],
I80105: [“Distr - Spare Parts”],
I90201: [“S&M - Sales 1”],
I95103: [“CS - After Sales Service”],
};
//Finally you set the values of box2
function SetFieldValues(cDeptName){
this.getField(“dropdown3”).setItems(accountData[cDeptName]);
}

//Custom Keystroke Dropdown 1
//if( event.willCommit ){
if(event.value == “–SELECT–”){
//app.alert(event.value)
//if nothing is chosen in box1 then box2 will be cleared

this.getField(“dropdown3”).clearItems();
}else {
//app.alert(event.value)
SetFieldValues(event.value);
}
//}
//ENDSCRIPT
main();

Please format your code by wrapping them in three backticks (```). Also, what are the errors?

Hi Ghukahr

Thanks for getting back to me so quickly.

When you say wrap the code with three backticks (```) would this be as per below?
Genie: (’’’["",“I30000”,“I30101”,“I30400”,“I30401”,“I30404”,“I30501”,“I30505”,“I30601”,“I30602-PSR”,“I30703”,“I51003 - PSR”,“I70000”,“I70199”,“I80000”,“I80101”,“I90201”,“I90299”]’’’),

To validate the script I’m using https://validatejavascript.com/ and it shows the below errors?

2:13 error Parsing error: Unexpected character ‘“’ 1 | var adpData = { > 2 | Genie: ["",“I30000”,“I30101”,“I30400”,“I30401”,“I30404”,“I30501”,“I30505”,“I30601”,“I30602-PSR”,“I30703”,“I51003 - PSR”,“I70000”,“I70199”,“I80000”,“I80101”,“I90201”,“I90299”] | ^ 3 | Pegson: ["",“60109”, “70000”,“60901”,“61202”,“30602”,“60106”,“90000”,“90301”,“30703”,“30501”,“30401”,“30102”,”30101”,”60204”,”60401/60210”,”60202”] 4 | Cranes UK: ["",“D60401”,“I80106”,“I30000”,“I80105”,“I90201”,“I95103”] 5 | };

No, like the picture below, click on the icon code and then paste your code :+1:

I think I am nearly there now Ghukahr, the only error message its generating is

Sorry I didn’t make myself clear, the ``` is not to fix your code, it is just to format your code in the forum so it have highlight and it’s pasted correctly.

What you have to do is:

  1. Click on the reply button
  2. Click on the code icon above the textarea where you type your reply (you can see the screenshot I posted above)
  3. Paste your code
  4. Send your reply

From there we’ll try to help you.


 Genie: ["",“I30000”,“I30101”,“I30400”,“I30401”,“I30404”,“I30501”,“I30505”,“I30601”,“I30602-PSR”,“I30703”,“I51003 - PSR”,“I70000”,“I70199”,“I80000”,“I80101”,“I90201”,“I90299”]
Pegson: ["",“60109”, “70000”,“60901”,“61202”,“30602”,“60106”,“90000”,“90301”,“30703”,“30501”,“30401”,“30102”,”30101”,”60204”,”60401/60210”,”60202”]
Cranes UK: ["",“D60401”,“I80106”,“I30000”,“I80105”,“I90201”,“I95103”]
 };
var accountData = {
 I30000: [“(302)Recharge - TFSE”],
I30101: [“(310)Recharge - Terex USA"],
 I30400: [“(293)HR”],
I30401: [“(304)Recharge - Terex Corp”],
I30404: [“(241)Training”],
I30501: [“(292)IT”],
I30505: [“(284)TMS”],
I30601: [“(306)Recharge”],
I30602-PSR: [“(272)Used Equipment”],
I30703: [“(200)Finance”],
I51003 – PSR: [“(240)Service”],
I70000: [“(240)Service”],
I70199: [“(272)Used Equipment”],
I80000: [“(220)Parts”],
I80101: [“(210)Inventory”],
I90201: [“(260)Sales”],
I90299: [“(261)Marketing”],
60109: [“(10-11)Production support General - Indirect”],
70000: [“(10-13)Crusher Design”],
60901: [“(10-15)Quality & Reliability - Indirect”],
61202: [“(10-16)Stores - Indirect”],
30602: [“(10-17)Maintenance - Indirect”],
60106: [“(10-25)Production Planning”],
90000: [“(10-40)Quarry Sales”],
90301: [“(10-47)Strategic Marketing”],
30703: [“(10-70)Accounts Department”],
30501: [“(10-72)IT”],
30401: [“(10-74)HR”],
30102: [“(10-75)MD’s Office”],
30101: [“(10-81)Fabrication - Direct”],
60204: [“(10-85)Quarry Plant Ass. Shop Bay 4 - Direct”],
60401/60210: [“(10-86)Quarry Machine Fitting Shop Bay 3 - Direct”],
60202: [“(10-89)Bay 2 Machine Shop - Direct”],
D60401: [“Machine Shop 1”],
I80106: [“Distr – Service”],
I30000: [“Business Support”],
I80105: [“Distr - Spare Parts”],
I90201: [“S&M - Sales 1”],
I95103: [“CS - After Sales Service”],
 };
 //Finally you set the values of box2
 function SetFieldValues(cDeptName){
 this.getField(“dropdown3”).setItems(accountData[cDeptName]);
 }

//Custom Keystroke Dropdown 1
 //if( event.willCommit ){
 if(event.value == “–SELECT–”){
//app.alert(event.value)
 //if nothing is chosen in box1 then box2 will be cleared

this.getField(“dropdown3”).clearItems();
 }else {
//app.alert(event.value)
 SetFieldValues(event.value);
 }
 //}
 //ENDSCRIPT
 main();

Thanks Ghukahr, I have just forwarded the script as you requested.