One way to do Tulip dropdowns from tables (and passing an ID)

So, it’s not uncommon to want to be able to select an item in a drop down and then pass the id of that value back for table updates. This is one such way, and a possible shortcut way at the end.

Let’s set up a quick table with some vehicles.

When you select the value in the drop down you don’t have an easy way to get back to the id.

One way is to concat the ROW_NUMBER onto the field. Chances are your data element doesn’t contain alt code 0151 so you can use this as your separator. https://www.alt-codes.net/ (Or whatever you prefer)

ā€”0151

So make a form trigger that loads the connector.

Then use the map_to_text_list(@Variable.Vehicles , ‘type’) to get it into a text array for use by the drop down.

Configure the Drop down, creating a Selected Item variable

Create a button to get the id.

First use a regex to grab the row number from off the Selected Item (use alt 0151)

regex_match(@Variable.Selected Item , '.*(?= ā€” )')

This drops it to an array, so grab the first element of that array.

Then we want to reference the original variable that we brought in from the table query (Vehicles) and then convert the ‘Extracted’ Index into an Integer so we can use it to reference the array position (-1 because the selected list is a zero based).

This writes out an array matching the selected item in the drop down. To use it:

Let’s say we want to update the color of one of these vehicles. Create the function to do a simple update based on the key.

Create an input variable for the color

Then create a button to call the function, and drill into the Selected Id -> id

Put in the color, click the button to get the id and then click the button to update the color.

I did run across a possible shortcut. It looks like TEXTTOINTEGER function tries to parse the first number it comes across, so maybe it reads up until a space? Anyways this means you can do just the below to grab the index.

I wish there was a way to grab the index of the selected item in the dropdown to make this more user friendly!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s