Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Using Tap Forms Pro › Picklist selection generates new values for a different pick list
- This topic has 7 replies, 3 voices, and was last updated 3 weeks, 3 days ago by
Glen B.
-
AuthorPosts
-
August 15, 2025 at 3:04 PM #52853
Glen BParticipantPerhaps I am approaching this wrong.
Simply put I have two Forms
Company
OrderCompany Form has multiple fields but only two that we are needing to work with for this problem
Company Name
Company StreetOn the Order Form there are two fields of interest
Company
StreetOn the Order Form Company is a Picklist from Company Form using Company Name field for the list
The problem trying to be solved is that every Company may have multiple Street addresses so on the Order Form I would like to have the field Street be a Picklist based off of the Company selected in the Company field.
My thoughts are:
1. Can a script be triggered on the selection of the Company from the Picklist that then generates a list of Street values for that company and those are then populated into the Picklist for Street? Not sure what happens between records as different Companies or different Streets are needed.
2. Or is there a relational link that can be done between the Street fields that utilizes a filter based on the Company selected.
Any direction or solutions are appreciated (hopefully I have explained the problem clearly)
regards,
August 17, 2025 at 11:38 PM #52858
BrendanKeymasterHi Glen,
So sorry for my delayed response.
1. A Field Script can be written which will run automatically when the Company is selected from a Pick List. You could then use the Prompter feature in the script engine to fetch a list of addresses from the selected company and let the user select from a popup which address to select. It’s a bit involved in writing a script to do that though. Not sure how your JavaScript skills are. Look at the Prompter instructions in the online user manual:
https://www.tapforms.com/help-mac/pro/en/topic/javascript-api
2. The Link to Form field popover view won’t filter the list of addresses based upon the selected Company Name. So that won’t work. Although you can type into the search field to find the company and it will filter the list. As long as the Company Street form also has a field that contains the company name.
Thanks,
Brendan
September 18, 2025 at 5:16 AM #52977
Glen BParticipantWell I just need a nudge on the code…I can successfully on the Order form select a Company from the pick list and a Popup shows the available street addresses for the company. I can select a street address and it populates the Order Street field.
But…the popup doesn’t close after the street is selected it remains open and I need to select cancel twice before it closes. That is the issue I have tried various ways to solve but get no where (other than going backwards and having the popup not show or have it so the street address selected never populates the Order Street field).
Attached is the code and I am hoping someone smart enough can spot the issue.
regards,
September 18, 2025 at 5:19 AM #52978
Glen BParticipantIt looks like the file did not attach so the code is below
============================================================/** * This script is designed to be run from a button on the Order form layout. * The button should be configured to "Run Script Field Script". */ function findAndSetStreet() { // The 'record' object is automatically available when a script is // run from a button on a record's layout. var currentRecord = record; var orderForm = form; if (!currentRecord) { Utils.alertWithMessage('Error', 'This script must be run from a record.'); return; } var companyForm = document.getFormNamed('Company'); if (!companyForm) { Utils.alertWithMessage('Script Error', 'Could not find the "Company" form.'); return; } // --- CONFIGURATION --- // On the line below, change "Company" to the EXACT name // of your company pick list field. var companyField = orderForm.getFieldNamed('Company'); // --------------------- var streetField = orderForm.getFieldNamed('Street'); if (!companyField || !streetField) { Utils.alertWithMessage('Script Error', 'Could not find your Company Pick List or Street fields.'); return; } var selectedCompanyName = currentRecord.getFieldValue(companyField.getId()); if (!selectedCompanyName || selectedCompanyName === '') { Utils.alertWithMessage('No Company', 'Please select a company before clicking this button.'); return; } var companyNameField = companyForm.getFieldNamed('Company Name'); var companyStreetField = companyForm.getFieldNamed('Company Street'); if (!companyNameField || !companyStreetField) { Utils.alertWithMessage('Script Error', 'Could not find "Company Name" or "Company Street" fields in the Company form.'); return; } var companyRecords = companyForm.fetchRecords(); var matchingStreets = []; for (var i = 0; i < companyRecords.length; i++) { var companyRecord = companyRecords; var companyName = companyRecord.getFieldValue(companyNameField.getId()); var street = companyRecord.getFieldValue(companyStreetField.getId()); if (companyName === selectedCompanyName && street && street !== '') { if (matchingStreets.indexOf(street) === -1) { matchingStreets.push(street); } } } if (matchingStreets.length === 0) { Utils.alertWithMessage('No Streets Found', 'No street addresses were found for ' + selectedCompanyName + '.'); currentRecord.setFieldValue(streetField.getId(), ''); return; } if (matchingStreets.length === 1) { currentRecord.setFieldValue(streetField.getId(), matchingStreets[0]); Utils.alertWithMessage('Street Set', 'The street address has been automatically set to: ' + matchingStreets[0]); return; } // Store references in variables that the callback can access var targetRecord = currentRecord; var targetStreetField = streetField; var prompterCallback = function(continued) { if (continued) { // Try to get the value using the global variable approach from your original code if (typeof selectedStreet !== 'undefined' && selectedStreet) { targetRecord.setFieldValue(targetStreetField.getId(), selectedStreet); } } }; var prompter = Prompter.new(); prompter.cancelButtonTitle = 'Cancel'; prompter.continueButtonTitle = 'Select'; prompter.addParameter('Select Street Address:', 'selectedStreet', 'popup', matchingStreets); prompter.show('Multiple Streets Found for ' + selectedCompanyName, prompterCallback); } // Check if this is running in a Script Field context (automatic execution) // vs being called from a button (manual execution) if (typeof record !== 'undefined' && record) { var companyField = form.getFieldNamed('Company'); if (companyField) { var companyValue = record.getFieldValue(companyField.getId()); // Only run if there's actually a company selected if (companyValue && companyValue !== '') { findAndSetStreet(); } } }
-
This reply was modified 3 weeks, 5 days ago by
Brendan.
September 18, 2025 at 8:26 AM #52981
Daniel LeuParticipantI noticed that you don’t use
document.saveAllChanges()
in order to save your modifications.I simplified the script to test the prompter function and it works as expected. Could you share a template file or even better a small document with a few sample records in order to reproduce the issue you see? Thanks!
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksSeptember 18, 2025 at 11:03 AM #52983
Glen BParticipantI hope the attachment comes through on this?
September 18, 2025 at 9:57 PM #52985
Daniel LeuParticipantYour script is executed several times. That’s why you get the repeated prompter.
1) You don’t want to trigger the script when changing the street field. To prevent this, use double quotes in
var streetField = orderForm.getFieldNamed("Street");
2) When setting a field value that should not trigger any script activity, use the optional third parameter:
targetRecord.setFieldValue(targetStreetField.getId(), selectedStreet, false);
Even with these changes, the script runs more than once.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksSeptember 20, 2025 at 8:50 AM #52999
Glen BParticipantThanks Daniel.
I have given up as this is a problem I created in which I thought would be easy to implement and use.
Maybe I should describe the issue I am trying to solve in the general sense and someone with the database experience or expertise would point me down the right way to approach the problem.
Anyways, I appreciate the efforts.
regards,
-
This reply was modified 3 weeks, 5 days ago by
-
AuthorPosts
You must be logged in to reply to this topic.