Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Can this be done? Call subforms based on dropdown linked to database

Avatar

Level 2

I am hoping to make a dynamic form and I'm wondering if it's possible.

I have a database with about 300 entries - pieces of farm property and a few bits of info about each of those properties. I want to create a form where users can choose the applicable piece of property from a dropdown list. Based on the property they select, another dropdown would populate with the crops associated with that property. Then based on the selection made in that dropdown, a specific form will be brought up.

For instance, someone selects property #102 from the dropdown. In the database, property #102 is associated with wheat, barley and corn, so the next dropdown would populate with those three crops. The user selects wheat from the dropdown and the wheat form would be called. 

I hope I explained that well enough.

Is that possible? And if it is possible, how complicated is it to do? Assuming I already have the database and subforms, would this be a weeks-long process to script, or would it be fairly straightforward?

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Yes,it could be done, here is one sample which should help : Dependent Drop down boxes (sample attached)

On the basis of selection (change event of second drop down), you can display/hide any subform.

-Wasil

View solution in original post

5 Replies

Avatar

Correct answer by
Employee Advisor

Yes,it could be done, here is one sample which should help : Dependent Drop down boxes (sample attached)

On the basis of selection (change event of second drop down), you can display/hide any subform.

-Wasil

Avatar

Level 2

Thank you! That is quite helpful.

Avatar

Level 2

One more question - as this form is to be distributed to outside users (with no control over their system or whether or not they have internet access), can the database be linked/contained within the document somehow?

Avatar

Employee Advisor

Yes, in a way you can put the data as part of the script. In the above form :

<script contentType="application/x-javascript" name="courtScript">// This script object controls the interaction between the court and PO Drop-down lists.

// The array contains the court and the corresponding PO.

var myCourts = new Array(new Array (7), new Array (6), new Array (8), new Array ());

// Create a two-dimensional array.

                                                                            // For each court, add a 'new Array(number of PO +1)'.

// Define the court and the corresponding PO.

// The array syntax is arrayName[index][index].

// The first index number represents the court,

// the second index number is the actual data value.

myCourts[0][0] = " ";        // The first items in the Drop-dowm Lists should be blank.

myCourts[0][1] = " ";

myCourts[1][0] = "Barnstable";    // The first data value is the court name,

myCourts[1][1] = "";  

myCourts[1][2] = "Smith";      // the rest are PO names.

myCourts[1][3] = "Brown";

myCourts[1][4] = "Jones";

myCourts[1][5] = "Green";

myCourts[1][6] = "Holiday";

myCourts[1][7] = "Nobody";

myCourts[2][0] = "Berkshire";

myCourts[2][1] = "";

myCourts[2][2] = "Green";

myCourts[2][3] = "Red";

myCourts[2][4] = "Yellow";

myCourts[2][5] = "Purple";

myCourts[2][6] = "Pink";

myCourts[3][0] = "Bristol";

myCourts[3][1] = "";

myCourts[3][2] = "Long";

myCourts[3][3] = "Short";

myCourts[3][4] = "Tall";

myCourts[3][5] = "Portly";

myCourts[3][6] = "Wide";

myCourts[3][7] = "Stout";

myCourts[3][8] = "Frail";

// This function will populate the court Drop-down List.

// This function is called from the initialize event of the court Drop-down List.

function getCourts(dropdownField)

{

   dropdownField.clearItems();

   for (var i=0; i &lt; myCourts.length; i++)

      dropdownField.addItem(myCourts[i][0]);

}

// This function will populate the PO Drop-down List for any event EXCEPT the change event.

// This function is called by the initialize event of the PO Drop-down List.

function getPOs(courtField, dropdownField)

{                                            

   dropdownField.clearItems();                             // Clear the items of the Drop-down List.

   for (var i=0; i &lt; myCourts.length; i++)             // Look through all the courts until we find the one that matches the court selected.

      if(myCourts[i][0] == courtField.rawValue)     // Check to see if they match.

      {

         for (var j=1; j &lt; myCourts[i].length; j++)     // When they match, add the POs to the Drop-down List.

         {

            dropdownField.addItem(myCourts[i][j]);

           }

         dropdownField.rawValue = myCourts[i][1];    // Display the first item in the list.

      }

}

// This function will populate the PO Drop-down List for the change event.

// This function is called by the change event of the court Drop-down List.

// The first parameter is simply a pointer to the xfa object model.

function getPOOther(myXfa, dropdownField)

{                                            

   dropdownField.clearItems();                            // Clear the items of the Drop-down list.

   for (var i=0; i &lt; myCourts.length; i++)            // Look through all the courts until we find the one that matches the court selected.

      if(myCourts[i][0] == myXfa.event.newText)        // Check to see if they match. Note: we have to use the event.newText in this case because

      {                                                    // the change hasn't been committed yet.

         for (var j=1; j &lt; myCourts[i].length; j++)     // When they match, add the states/provinces to the Drop-down List.

         {

            dropdownField.addItem(myCourts[i][j]);

          }

         dropdownField.rawValue = myCourts[i][1];    // Display the first item in the list.

      }

}</script>

-Wasil


P.S.  For the form to be interactive in Adobe Reader, it must be Reader Extended