Forms Table dropdown option selected, to run separate query

Tom Wisneski asked on May 29, 2020 18:31

Question. Using a Kentico forms table which has a dropdownlist with options. Depending on a given option selected, we would like to run a separate query. How would this be done? Some background: using a form table for the built email notification functionality. We have another table, a Custom Table with values that are used (Model IDs, Model Names, Liters, Voltage, etc.). Depending on what option is selected in the Kentico form, then we would query the Custom table for those values. Hope the question and info makes sense. Just trying to figure the easiest way to make this happen. Thanks.

Correct Answer

Dmitry Bastron answered on May 29, 2020 23:27

Tom, this can be done like this:

  1. First form field, let's call it Frequency, is configured as:

    • Data type: Text
    • Form control: Drop-down list
    • Data source: list of options
      • 50Hz
      • 60Hz
    • Has depending fields: true
  2. Second form field, GeneratorModel is configured as:

    • Data type: Text
    • Form control: Drop-down list
    • Data source: SQL Query (will be below)
    • Depends on another field: true

Query:

select GeneratorCode,  --this is drop-down item value
       GeneratorName   --this is drop-down item display name
from customtable_Generators
where GeneratorFrequency = '{% Fields["Frequency"].Value #%}'

When you configure form fields, you can use this macro to get the value of another field on the same form: {% Fields["Frequency"].Value #%}

0 votesVote for this answer Unmark Correct answer

Recent Answers


Dmitry Bastron answered on May 29, 2020 19:00

Hi Tom,

Fortunately Forms autoresponder and notification emails support Kentico macro methods. You can read more about using it here. So you can try using this macro in your email:

{% GlobalObjects.CustomTables["customtable.Test"].Items.Where("YourCustomTableFieldName = '" + YourFormFieldName + "'").FirstItem.YourCustomTableOtherFieldName %}

Also have a look at macro methods syntax as it can be useful.

0 votesVote for this answer Mark as a Correct answer

Tom Wisneski answered on May 29, 2020 20:15 (last edited on May 29, 2020 20:20)

Dmitry - Thanks so much for taking the time to reply to my question. Though I am somewhat confused by the answer. So I'll try phrasing the scenario a different way. One table (a Kentico Form table), will collect the user input. On this table there is a dropdown, that in this example is either 50Hz or 60Hz. Depending on which option the user selects, then another dropdown will be populated with values (generator models). These values are stored in a Custom Table. So in your reply you mention using Macro's to reference a Custom Table. If a Macro is the correct way to do this or is it a SQL query (something like "Select * from CustomTable where Frequency = 50"...or 60). Thanks. Tom

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on May 29, 2020 20:30

OK, I got you now, I thought you are combining an email but apparently it's slightly different question.

What version of Kentico are you using and is it Portal Engine or MVC? Depending on this the solution will be different.

0 votesVote for this answer Mark as a Correct answer

Tom Wisneski answered on May 29, 2020 20:35

Dmitry, sorry about the initial misunderstanding. I just stated about the email requirements in the initial question -- because in the past I got slammed on the message boards for using the Kentico Form rather than a Custom table to collect the user data. Anyways, version v11.0.48. Our sites are in WebForms ASP.Net (not using MVC). Thanks.

0 votesVote for this answer Mark as a Correct answer

Tom Wisneski answered on May 29, 2020 23:32

Dmitry....Thank you. Yes, this looks exactly like what I need (your latest post). Have a good rest of your day! :) Tom

0 votesVote for this answer Mark as a Correct answer

Tom Wisneski answered on June 1, 2020 15:26

Dmitry...thank you again for helping me out last week. Your answer was 100% correct. Thanks! Tom

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.