Skip to main content
cataholic_1
Known Participant
September 27, 2022
Answered

Dependent Drop Down List not working

  • September 27, 2022
  • 2 replies
  • 2672 views

I have created two drop-down lists on my form, the master is called Department and the dependent is called Division.

When someone selects a department, such as "CAO", the Division drop-down should include options such as "HR", "Comms", or "Ec Dev" to select from. 

The following is the Java Script that I have entered into the Custom Keystroke Script area of the Department drop-down list properties, which I based on this youtube video https://www.youtube.com/watch?v=QTWDw0va2D4 but it doesn't seem to be working. Although I'm not getting any error messages, nothing is populating in the Division drop-down.

Could someone please help me figure out what I'm missing? Did I put the script in the wrong area?

Thanks!

var DivisionList = this.getField("Division");

if(event.willCommit)
{
switch(event.value){

case "CAO":
  DivisionList.setDivision(["-select CAO-", "HR", "EcDev", "Communications"]);
break;

case "Community Services":
  DivisionList.setDivision(["-select Community Services-", "Facilities & Parks", "Cemeteries", "Project Management", "Public & Open Spaces", "Recreation & Culture", "Cultural Development"]);
break;

case "Corporate Services":
  DivisionList.setDivision(["-select Corporate Services-", "Legislation", "Clerks"]);
break;

case "Finance, Administration & Innovation":
  DivisionList.setDivision(["-Finance, Administration & Innovation-", "Finance", "Tax Billing", "Accounting", "Procurement", "IT Services", "Utility Billing"]);
break;

case "Fire & Emergency Services":
  DivisionList.setDivision(["-Fire & Emergency Services-", "Fire Suppression", "Fire Prevention"]);
break;

case "Planning & Development":
  DivisionList.setDivision(["-Planning & Development-", "By-Law", "Planning", "Building"]);
break;

case "Public Works":
  DivisionList.setDivison(["-Public Works-", "Climate Change", "Environmental Services", "Project Manager's Office", "Roads & Fleet", "Technical Services", "Transit", "Water & Waste Water"]);
break;

default:
  DivisionList.setDivision([""]);
break;


}

}

 

 

This topic has been closed for replies.
Correct answer Nesa Nurani

You should replace 'setDivision' with 'setItems' and also for default you can use clearItems() and remove last break.

Try this:

var DivisionList = this.getField("Division");

if(event.willCommit)
{
switch(event.value){

case "CAO":
  DivisionList.setItems(["-select CAO-", "HR", "EcDev", "Communications"]);
break;

case "Community Services":
  DivisionList.setItems(["-select Community Services-", "Facilities & Parks", "Cemeteries", "Project Management", "Public & Open Spaces", "Recreation & Culture", "Cultural Development"]);
break;

case "Corporate Services":
  DivisionList.setItems(["-select Corporate Services-", "Legislation", "Clerks"]);
break;

case "Finance, Administration & Innovation":
  DivisionList.setItems(["-Finance, Administration & Innovation-", "Finance", "Tax Billing", "Accounting", "Procurement", "IT Services", "Utility Billing"]);
break;

case "Fire & Emergency Services":
  DivisionList.setItems(["-Fire & Emergency Services-", "Fire Suppression", "Fire Prevention"]);
break;

case "Planning & Development":
  DivisionList.setItems(["-Planning & Development-", "By-Law", "Planning", "Building"]);
break;

case "Public Works":
  DivisionList.setItems(["-Public Works-", "Climate Change", "Environmental Services", "Project Manager's Office", "Roads & Fleet", "Technical Services", "Transit", "Water & Waste Water"]);
break;

default:
  DivisionList.clearItems();}}

2 replies

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
September 28, 2022

You should replace 'setDivision' with 'setItems' and also for default you can use clearItems() and remove last break.

Try this:

var DivisionList = this.getField("Division");

if(event.willCommit)
{
switch(event.value){

case "CAO":
  DivisionList.setItems(["-select CAO-", "HR", "EcDev", "Communications"]);
break;

case "Community Services":
  DivisionList.setItems(["-select Community Services-", "Facilities & Parks", "Cemeteries", "Project Management", "Public & Open Spaces", "Recreation & Culture", "Cultural Development"]);
break;

case "Corporate Services":
  DivisionList.setItems(["-select Corporate Services-", "Legislation", "Clerks"]);
break;

case "Finance, Administration & Innovation":
  DivisionList.setItems(["-Finance, Administration & Innovation-", "Finance", "Tax Billing", "Accounting", "Procurement", "IT Services", "Utility Billing"]);
break;

case "Fire & Emergency Services":
  DivisionList.setItems(["-Fire & Emergency Services-", "Fire Suppression", "Fire Prevention"]);
break;

case "Planning & Development":
  DivisionList.setItems(["-Planning & Development-", "By-Law", "Planning", "Building"]);
break;

case "Public Works":
  DivisionList.setItems(["-Public Works-", "Climate Change", "Environmental Services", "Project Manager's Office", "Roads & Fleet", "Technical Services", "Transit", "Water & Waste Water"]);
break;

default:
  DivisionList.clearItems();}}
cataholic_1
Known Participant
September 30, 2022

Thank you!! That works perfectly!

Bernd Alheit
Community Expert
Community Expert
September 27, 2022

Use setItems, not setDevision.

Look at the video. 

cataholic_1
Known Participant
September 28, 2022

I tried to replace all setDivision with setItems, as per your suggestion, but that didn't work either.

I assumed that I would need to use the name of the dropdown instead of Items, as that is what the video shows. Does it not need to match what my dropdown is named? If I use setItems, but the dependent dropdown is named Division, how does it know where to put the information?

Bernd Alheit
Community Expert
Community Expert
September 28, 2022