Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
September 18, 2025 at 9:57 PM #52985
Daniel Leu
ParticipantYour 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 18, 2025 at 8:26 AM #52981Daniel Leu
ParticipantI 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 5:32 AM #52979In reply to: Manual Sorting Feature Looks Promising!
Glen B
Participant/**
* 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();
}
}
}September 18, 2025 at 5:19 AM #52978Glen B
ParticipantIt 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 5 months, 3 weeks ago by
Brendan.
September 17, 2025 at 1:57 AM #52972Peter Riley
ParticipantWonderful! Thanks Daniel.
I did some research into JS methods but have to admit the code was way above my level so, elegant or not(!), your solution is just what I need.
I get a console error if the table is blank in a record (because that particular meal has been eaten and the row deleted) but that doesn’t seem to affect execution of the script.
Cheers
Peter
September 16, 2025 at 3:19 AM #52968Topic: Field script to extract earliest date from table field
in forum Script TalkPeter Riley
ParticipantMy freezer inventory db (template attached) has a table field in which I record each time I make a batch of a particular recipe. The table field’s fields include things like the quantity of meals frozen, and the date frozen. I have a field script that correctly populates a Total field with the total remaining meals from each record’s table, and I have tried to do the same with a date field – ‘Earliest freeze date’ – to extract the oldest frozen meal from that recipe, using the following script so I can then include the field in a search:
record.getMinOfLinkedFieldForField('fld-7b64bb627a8a4beaadacd625f3c4e46a', 'fld-557ef5d4175949a8a0ac0b7b3cf5f932');This is the total script – ie there is no function – but for a batch of meals frozen on 21 April 2025 and 14 September 2025 I get ’21 Jan 1970 at 05:46:30′ in the script field. The console shows the result of running the script as 1745190000. The Result Type is set to ‘Date’.
Is getMinOfLinkedField not appropriate for a date calculation?
I’m assuming it’s not possible to script a search through the freeze dates of the table field?
Thanks
Attachments:
You must be logged in to view attached files.September 13, 2025 at 1:09 PM #52965Topic: Script Editor Will Not Paste
in forum Using Tap Forms 5Shane
ParticipantHey all,
For some reason TF5 can copy but not paste (see screenshot). I tested it in Tap Forms Pro which works fine. The option to paste is greyed out, nor can I use commond+V. Anyone else notice this problem?
I tried going into the Mac’s security and privacy settings and allowing TF5 to control the computer, then relaunching but it didn’t do anything.
Attachments:
You must be logged in to view attached files.September 11, 2025 at 10:37 PM #52963Daniel Leu
ParticipantSecond time I’m trying to post an answer…. the first time caused the forum to crash :-(. So this answer will be a bit shorter.
The field script has an error. The dash
-in the field ids is not a dash and therefore, no value is read. I modified the script to call the form script in the Coins form:(function() { const ct = record.getFieldValue('fld-1231556e0f234de9b2d85f50225b8135'); const yr = record.getFieldValue('fld-4b84b047badd4d4cbb4a67ef6839522f'); const mm = record.getFieldValue('fld-adb0be16f1a347dbbecc4ef562d779a7'); if (ct && yr && mm) { console.log("condition met") document.getFormNamed('Coins').runScriptNamed('Variety Prompt'); } return ''; })();When running the Variety Prompt script, I run into an error where the constants were already defined. This has to do with how javascript is handled within Tap Forms Pro. So I moved that section inside your function:
// === Script === (function () { // === CONFIG (your IDs kept as-is) === const COINS_FORM_NAME = 'Coins'; const MINTAGE_FORM_NAME = 'Coin Mintage'; const COINS_FIELDS = { coinType: 'fld-1231556e0f234de9b2d85f50225b8135', year: 'fld-4b84b047badd4d4cbb4a67ef6839522f', mintMark: 'fld-adb0be16f1a347dbbecc4ef562d779a7', variety: 'fld-2a73d81d137e4f718378819f5e4d54e0' }; const MINTAGE_FIELDS = { coinType: 'fld-fdf93db206d141bd956d8c9e7634f25e', year: 'fld-9579d7c74e88414daf27ccbc5d4e0346', mintMark: 'fld-8d72d0971ed34c2c9de6c03d240e9543', variety: 'fld-f76a6eb7ed0c4ae28b77fc6fdf055d53' }; if (typeof record === 'undefined' || !record) { ...Now it seems to work. Good luck!
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksSeptember 10, 2025 at 6:48 PM #52952Daniel Leu
ParticipantYou definitely can run a form or document script from a field script. I do this all the time. For a form script, you can use
document.getFormNamed('demo').runScriptNamed('test');, for a document script usedocument.runScriptNamed('test');.Do you have a test file you can share? You can email it if you prefer.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksSeptember 10, 2025 at 4:03 PM #52949Mark Moran
ParticipantAgain thanks for your help.
My research says that I can use the prompter in a field script. Also, I can’t run a form script from a field script. This eliminates the process I want to accomplish. I want it to prompt for the variety field from the records in the coin mintage form.
September 8, 2025 at 4:11 PM #52939In reply to: Hiding form fields
Daniel Leu
ParticipantAutomatically, no. But you could have a button that launches a script that selects the layout based on certain field values.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksSeptember 8, 2025 at 9:17 AM #52937In reply to: Hiding form fields
Brendan
KeymasterHi Peter,
Well, there is a hide field setting for a field, but it hides the field for every record.
One solution to the problem though is on the Mac version to create different layouts. With custom layouts you don’t have to have every field on every layout. So one layout can have the Diameter field and another layout can have the Width and Length fields.
Although you can control the hide field property using a script which can run when you select a value from a Pick List, scripts don’t run just by switching records, So even if the field was hidden when you selected a value, switching records wouldn’t automatically re-show that field if the next record had a different value from your Pick List.
So not exactly what you’re looking for here though.
Thanks,
Brendan
September 4, 2025 at 11:06 AM #52932Mark Moran
ParticipantThanks again. Knowing how the field script trigger works helps.
The choices are only valid values and nothing else. Still no clue where the unspecified is coming from.
Mark
September 4, 2025 at 8:49 AM #52928Daniel Leu
Participantre “unspecified”: To start with, I would check that the list of values really only contains valid values and nothing else. Add a
console.log(choises.join(" | "))before the prompter code.Re “field script trigger”. This is from an older post from Brendan:
… my Objective-C code scans your source code to determine which fields you’re referencing in the script by looking for the text .getFieldValue(‘fld-…..’). Or when using a variable instead of (‘fld-….’).
When one of the referenced fields changes, the field script is triggered.
Hope this helps!
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksSeptember 4, 2025 at 3:35 AM #52926Mark Moran
ParticipantThanks Daniel. Extremely helpful as usual.
Totally missed the default value. Still has “unspecified” as an option. But at least it now defaults to possible answer I would want.
Using the field script… I’m not clear on field scripts, they are triggered when exactly? Are field scripts triggered when another script uses thisRecord.getFieldVlaue(‘fld-xxx’) as I think you’re saying above? Kind of a chicken and egg thing, where is the thisRecord.getFieldValue used that it triggers the field script or the form script?
-
This reply was modified 5 months, 3 weeks ago by
-
AuthorSearch Results