Auto fill secondary field based on selection of primary field

Hello everyone,
I am new here and this is my first question.
I am trying to create an app which uses Google Sheet as data source.
I have got two columns which are customer_name and contact_no. I have created two select fields. What I want here is if I select Customer A in my primary field the contact no associated with that customer should auto populate in secondary field which I am unable to do so.
Any help will be appreciated. Thanks :slightly_smiling_face:

Hey @Atul88, welcome to the fam :hugs:

It would be best to work off a unique/primary key for all your records. Let's assume that's not the case in your sheet.

What's the reason for the second input being a select component? As far as I understand you can use a normal text/number input.

Set the default value of the second input to something like this:

{{_.find(query.data, {customer_name: select.value}).contact_no}}

If you do have something unique to filter your customers by (id, email, etc) I would use that field.

Does that work for you?

2 Likes

That worked like a charm :smiley: Thanks alot :+1:
Now if I am going to give id as a primary key how would the query look like? I am curious.

Do you mean in the same context? Something like this? :slight_smile:

{{_.find(query.data, {id: select.value}).contact_no}}

^That code does the same thing as minijohn's code, but instead, matches an id to the select.value (instead of matching a customer_name).

If this isn't what you were asking about, let me know and I'd be happy to help!

for some reason that query didn't work maybe because I am using customer_name in select field.

That would make sense! Well, if you were using the ID in the select component, then the above code should hopefully work for you :slightly_smiling_face: