I have a drop down list that has 2 choices in it. Both of them also have values assigned to them (301 and 302). I want to be able to perform a database lookup that will pull back the value (301 or 302 or both) and select the option in the drop-down list. Is this possible with the current version of Forms?
Question
Question
Select Drop-Down Choice Based on Returned Value from Lookup
Answer
This is probably a candidate for a SQL stored procedure lookup rule, since you can use multiple tables and more complicated logic there. If you're using an Oracle data source, this might be more difficult or impossible.
Replies
It should be possible. Are you matching the choices in the database or the values? If you're matching the choices, it shouldn't be too much work to fill a field with the appropriate value and then select the value in the drop-down. If you're trying to match the value, it should also be possible but might require a bit more work on the lookup.
I'm trying to match on the value. In the form a users email address is entered. based on the email address, it does a lookup in a student information system (SIS) for that teachers name and school id. It populates the teachers name field. That part works correctly.
I have a drop-down with each schools name in it and the value for them is a school id. I want to match the school id that is returned from the SIS with the choice value in the drop-down field.
So you're already returning the school ID, you just want to use that to select the appropriate choice in a drop-down list?
Correct. The way I've been trying replaces the school name with the school id though, rather than just looking to see what the returned school id is and matching it with the value of an item in the drop-down.
To add to this so you have a little more understanding, there is a table for Teachers and a table for Schools. So in the Teachers table it just references the school id, but not the school name. The school name is in the Schools table.
Try something like this:
Fill a field with the correct school ID with your lookup rule. Give this field the filledField class.
Create a drop-down with values that match the school ID values. Give this field the dropdown class.
Use the following JavaScript:
$(document).ready(function() { $('.filledField input').change(function() { $('.dropdown').find('option[value="' + $(this).val() + '"]').prop('selected', true); }); });
I have another twist to throw in to this. Some teachers have multiple school id's. Can I fill a drop-down field with all returned values and then somehow use that to populate the school names in the drop-down list with just those options?
I think I'm confused about how you want this to work. You want to select a teacher and then see a drop-down field filled with all the school names associated with that teacher?
Correct. So when a teacher is selected there may be multiple school ids associated with them. I would populate a school id drop-down list with the ids. I would then have another drop-down that would have the school names and the school ids as their values that would be populated with only the returned values from the initial teacher lookup and the school ids associated with them. I hope that helps clear it up.
Can you perform a lookup on the teacher that returns the schools by name in a drop-down list? It seems like the school ID step is unnecessary.
I cannot. The teacher table has the teachers name and school id. The school table has the school id and school name, so I have to associate the school id from the teachers table to the school table based on school id.
This is probably a candidate for a SQL stored procedure lookup rule, since you can use multiple tables and more complicated logic there. If you're using an Oracle data source, this might be more difficult or impossible.
Unfortunately it is in an Oracle database.
can you create a view linking your school and teacher tables and then use that for your lookup?
I will have to talk to our SIS people to see what they are able to do. If not, I may just make the teacher choose their school manually. Thank you guys for your help.