Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Script Talk › Totally lost on script
- This topic has 4 replies, 2 voices, and was last updated 1 month, 1 week ago by
Daniel Leu.
-
AuthorPosts
-
November 15, 2025 at 4:01 PM #53219
john blumaParticipantI have two forms
Parent form- Property. Fields PropId and OwnerName. One to many link to child.
Child file Payments. Fields PaymentFor and PayeeI would like to copy. PropId -> PaymentFor. and OwnerName -> Payee
automatically when the child record is created.I have lloked at other posts in this forum and I just don’t get it.
Can you help me get started on this?November 16, 2025 at 10:42 AM #53220
Daniel LeuParticipantIn this case, it is easier to use a calculation field.
First, check in the Property form that ‘show reverse relationship’ is selected for the one-to-man relationship. Then in the Payments form, create the two fields and select Calculation as the field type. For the formula, you now can select the respective field from the parent from. Return type must match the field type. That’s it.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksNovember 16, 2025 at 4:05 PM #53221
Daniel LeuParticipantFor completeness, this is how the script would look like.
function Script() { const property_id = 'fld-xxx'; // set according to your form const ownerName__property_id = 'fld-xxx'; // set according to your form // get properties record // (the result is an array, but since it's a one-to-many relationship, just take the first entry) const property = record.getFieldValue(property_id)[0]; // get owner name const ownerName = property.getFieldValue(ownerName__property_id); return ownerName; } Script();For this to work, the reverse relationship option needs to be set and the return type of the script must match the field type from the property form.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksNovember 24, 2025 at 1:57 PM #53288
john blumaParticipantI am still lost on scripts on parent child relationships. I am trying to populate two fields
on the payment(child)form with values from property (parent form).I don’t understand _ is the paarent record already in memory or di I need to
do. read dto retrieve the data. Am I supposed to pass the variable names as varname of ‘varname’?I even tried ChatGPT to generate the following script andit errors out
// ————————————–
// Parent form field IDs (Property)
// ————————————–
const PROP_PROPID = ‘fld-6716b8eda66d44339f6ba08f37334ea8’;
const PROP_LASTNAME = ‘fld-89a63a63d13048e6847d747cc9a2f5df’;
const LINK_TO_PROPERTY = ‘fld-e476bcbca1a9425ebe799373abc1ab73’; // inverse relationship link// ————————————–
// Child form field IDs (Payment)
// ————————————–
const PMT_PROP = ‘fld-2a06b08909054396ae904b3fb2f4d04c’;
const PMT_PAYEE = ‘fld-f050a0f16e1b41b8bf62ed96e567032f’;// ————————————–
// Get the linked Property record
// ————————————–
var parentRecord = record.getFieldValue(LINK_TO_PROPERTY);if (parentRecord == null) {
// No linked property; exit safely
return;
}// ————————————–
// Read values from the Property record
// ————————————–
var propId = parentRecord.getFieldValue(PROP_PROPID);
var lastName = parentRecord.getFieldValue(PROP_LASTNAME);// ————————————–
// Write values to the Payment fields
// ————————————–
record.setFieldValue(PMT_PROP, propId);
record.setFieldValue(PMT_PAYEE, lastName);Can you make it clear to a dinosaur Cobol programmer?
Are there any example forms that illustrate a working link between records
and use scripts to manipjulate data?Thanks for any help you can give
November 24, 2025 at 4:27 PM #53299
Daniel LeuParticipantHi John,
Please try following. Without having access to your document, I can’t verify the script, but hopefully, it works.
function updateProperty(){ // ————————————– // Parent form field IDs (Property) // ————————————– const PROP_PROPID = ‘fld-6716b8eda66d44339f6ba08f37334ea8’; const PROP_LASTNAME = ‘fld-89a63a63d13048e6847d747cc9a2f5df’; const LINK_TO_PROPERTY = ‘fld-e476bcbca1a9425ebe799373abc1ab73’; // inverse relationship link // ————————————– // Child form field IDs (Payment) // ————————————– const PMT_PROP = ‘fld-2a06b08909054396ae904b3fb2f4d04c’; const PMT_PAYEE = ‘fld-f050a0f16e1b41b8bf62ed96e567032f’; // ————————————– // Get the linked Property record // ————————————– var parentRecord = record.getFieldValue(LINK_TO_PROPERTY); if (parentRecord == null || parentRecord.length == 0 ) { // No linked property; exit safely console.log('No linked property', "#ff0000"); return; } // parent record is an array, extract first element if (parentRecord.length = 1) { parentRecord = parentRecord[0]; } else { console.log('Multiple linked properties', "#ff0000"); return; } // ————————————– // Read values from the Property record // ————————————– var propId = parentRecord.getFieldValue(PROP_PROPID); var lastName = parentRecord.getFieldValue(PROP_LASTNAME); // ————————————– // Write values to the Payment fields // ————————————– record.setFieldValue(PMT_PROP, propId); record.setFieldValue(PMT_PAYEE, lastName); document.saveAllChanges(); return; } updateProperty();Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks -
AuthorPosts
You must be logged in to reply to this topic.