Switch statement for dropdown select based on previous selection

Hi, i'm trying to run a switch statement to query the dropdown options within a select, i'm having trouble with what seems to be the format of the Value logic in my head (maybe there's an error with the code logic also).

What should happen is the following:

  • I have a Json for data source, where I have a series of entity_levels per entity_type.
  • On the previous select the user selects an entity_type, and next dropdown should show all related entity_levels for that selected entity_type.
  • User select entity_level

For some reason, the code I wrote is not working.
I'll add a screenshot of how i'm doing it:

My Data Source code:

{
   "ITF": [
      {
         "entity_level": {
            "level": "ITF - 1"
            }
      },
      {
         "entity_level": {
            "level": "ITF - 2"
            }
      },
      {
         "entity_level": {
            "level": "ITF - 3"
            }
      },
      {
         "entity_level": {
            "level": "ITF - 4"
            }
      }
   ],
   "IC": [
      {
         "entity_level": {
            "level": "IC - 2"
            }
      }
   ],
   "SOFIPO": [
      {
         "entity_level": {
            "level": "SOFIPO - 1"
            }
      }
   ],
   "SOFOM": [
      {
         "entity_level": {
            "level": "SOFOM - 1"
            }
      }
   ]
}

And my switch value logic :

{{switch (entity_type_select.value) {
  case "ITF":
    level = item.ITF.entity_level.level;
    break;
  case "IC":
    level = item.IC.entity_level.level;
    break;
  case "SOFIPO":
     level = item.SOFIPO.entity_level.level;
    break;
  case "SOFOM":
    level = item.SOFOM.entity_level.level
    break;
  default:
    level = "None";
}
}}

What i'm trying do use here is this: JavaScript Switch Statement

Here is how I would accomplish what I think you're trying to accomplish:

Create a Javascript Transformer Query with code like this:

switch ({{ entity_type_select.value }}) {
  case "ITF":
    return [
      {
         "entity_level": {
            "level": "ITF - 1"
            }
      },
      {
         "entity_level": {
            "level": "ITF - 2"
            }
      },
      {
         "entity_level": {
            "level": "ITF - 3"
            }
      },
      {
         "entity_level": {
            "level": "ITF - 4"
            }
      }
   ];
    break;
  case "IC":
    return [
      {
         "entity_level": {
            "level": "IC - 2"
            }
      }
   ];
    break;
  case "SOFIPO":
    return [
      {
         "entity_level": {
            "level": "SOFIPO - 1"
            }
      }
    ];
    break;
  case "SOFOM":
    return [
      {
         "entity_level": {
            "level": "SOFOM - 1"
            }
      }
    ];
    break;
  default:
    return [];
}

Then, set the data source for your level select component to the output of that Javascript Transform query.

My test app:
test2.json (8.0 KB)

Thank you @benbarry , this was really helpful, solved my problem perfectly!
Thank you for your time and detail sharing screenshots and your json