Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Using Tap Forms 5 › Calculation to auto fill a text field from a child link
- This topic has 7 replies, 3 voices, and was last updated 6 years, 7 months ago by
Ron.
-
AuthorPosts
-
November 8, 2018 at 3:09 AM #31716
Deborah TaylorParticipantHello,
I’m sorry if the topic title doesn’t make sense, but…
I have two forms linked by a join (A story form as the parent, and an episode details form as the child, linked by a unique reference number.) I want to be able to auto-fill a story title field in the child form, from the parent form, but the calculation option only allows me to return a ‘count’ of the text field. Is there a way I can change the ‘Count’ to simply the text contents from the parent field?
November 8, 2018 at 3:56 PM #31726
BrendanKeymasterHi Deborah,
The reason this doesn’t work the way you would like it to is because a Join Link Type works basically the same way as a Many to Many. That is, you can actually have multiple parent records that all join to the same set of child records using the Join fields.
So that means that a child cannot get access to just one parent record via the Calculation field.
However, this is possible by using a Script field and having Tap Forms get the first parent record from the array of parent records and then picking out the value for the field from the parent record.
November 9, 2018 at 8:33 AM #31733
RonParticipantI have attempted to create a script field to return the value from a parent record without success. Could you please give a sample of your script.
Thanks,
RonNovember 9, 2018 at 7:31 PM #31736
BrendanKeymasterHi Ron,
This is how I did it in one example:
var from_clients = record.getFieldValue('fld-d7bdd4c315034d85a91513258bad79d1'); if (from_clients) { var first_name = from_clients[0].getFieldValue('fld-9d1bca52fb894f75a01b29fbd789d198'); var last_name = from_clients[0].getFieldValue('fld-051eefffbb93476e9e9d65d149641169'); first_name + ' ' + last_name; }
November 10, 2018 at 9:41 AM #31737
RonParticipantThanks for the example. I was able to adapt it to my form and when I run the script it returns the expected result, but it is not displayed in the script field on the layout. The console log returns this error:
s_Doc: TypeError: undefined is not an object (evaluating ‘med_doctor[0].getFieldValue’), column:25, line:3
s_Doc is the name of the script field.var med_doctor = record.getFieldValue('fld-84c907c7af3c49daa19ca1e30975bc1b'); if(med_doctor){ var Name = med_doctor[0].getFieldValue('fld-b1cfe8adec9b4d7397683b068a262cc2'); Name; }
med_doctor is the parent form and the var Name receives the correct value from the Name field of med_doctor.
The error does not show in the script edit window when the run button is clicked, it only shows in the console if I click the save button and then open the log.November 10, 2018 at 11:05 AM #31738
RonParticipantAfter refreshing the record single column list the script field displays the correct result. The console log continues to display the same error.
November 10, 2018 at 12:42 PM #31739
BrendanKeymasterWhat kind of relationship are you using?
There’s a bug right now where it’s returning the first object instead of an array from the inverse of a Join relationship.
Maybe if you email me your form template I can take a closer look.
November 10, 2018 at 4:34 PM #31740
RonParticipantIt is a many to many. The script returns the correct value but when looking at the console log it gives the error.
-
AuthorPosts
You must be logged in to reply to this topic.