Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Tap Forms Template Exchange › Showing all child records in parent form / ParentChildCollection
- This topic has 1 reply, 2 voices, and was last updated 8 months, 3 weeks ago by Brendan.
Viewing 1 reply thread
-
AuthorPosts
-
February 26, 2024 at 12:53 AM #50553
FrAnkschParticipantI was looking for a way, to collect all linked records of a 1:n related child form within one note filed of the parent form, in order to use these information for further purposes.Since I am NOT familiar with software development and an absolutely newbie to scripting, I was searching the TF forums, and with the help of theChild Records Loop
snippet and some tips and examples Brendan published here in the forum, I built a template for “Collecting Child Records in the Parent form”, that works as I expected (I am on iOS, but the template should work on mac as well).I’m quite sure there are many other “non-software-development” users with minor scripting skills, so I prepared the templates with “speaking” names in the hope that it is understandable even for newbies.Sorry programmers, this is a beginners guide ;-)There are 2 forms:– ParentForm (PF)– ChildForm (CF)Within the CF there are 4 different records (children), each with several properties. In one additional field “AllProperties” I put all properties for each child together (calculation field, separate field values are connected via “concat” formula).The PF is linked with the CF via “1:n relation”. Within this PF there are 2 records (Parent1 and Parent2). Via the field “children” (relation field to child form), each Parent is linked with 2 children.You can select the children with the “selection checkbox”.Then there is a calculation field “children count” which shows automatically the number of selected children for each Parent.Additionally there is a note field “CollectionOfChildren”, which automatically shows the information for the “AllProperties” field for all linked children, one line for each child. Since this is one field with one text (consisting of all properties of all linked children), the text is very clear at a glance and is e.g. printed very nice or could be used for further purposes.The information for this target “note field” is generated in a script field “ScriptCollectChildren”, which is hidden and thus not visible in the form (only when you edit the form).The script code is listed below, you do NOT have to adapt the code anyhow, just replace the three (red) fieldIDs (fld-4e07f10f46………) in the upper part of the code.You can use this forms and adapt it according to your needs, or you can implement such fields to your already existing forms, copy the script code, paste it into your script fiel and replace the field IDs with yours.I hope this template (and/or the script) helps some of you, at least if you are a “rookie” like I am.ScriptCode (@programmers: sorry for bad indentation, this was written in TF iOS app)function CollectChildren() {var parentform_Children_id = ‘fld-4e07f10f46c84c0c99c5ca723ee42ad5’;//table of sourcedata (1:n LinkField to ChildForm)var parentform_Children = record.getFieldValue(parentform_Children_id); //datasets of sourcedatavar childform_RequiredProperty_id = ‘fld-570a6131139842288f18683e91833f6c’;//field of interest of sourcedatavar parentform_CollectionOfChildren_id = ‘fld-557c63ce9156491e8f8891b00c0def5b’; //tagetfield for collected data from field of interestvar temp_CurrentChild = []; //array for collecting data//running through all datasets & collecting data into temp. arrayfor (var index = 0, count = parentform_Children.length; index < count; index++){var childform_RequiredProperty = parentform_Children[index].getFieldValue(childform_RequiredProperty_id);if (childform_RequiredProperty) {temp_CurrentChild.push(childform_RequiredProperty);}}//joining collected data from temp. array into temp. variablevar temp_ChildrenList = temp_CurrentChild.join(“,\r”);//writing joined collection from temp. variable into target fieldrecord.setFieldValue(parentform_CollectionOfChildren_id, temp_ChildrenList);return temp_ChildrenList;form.saveAllChanges();}CollectChildren();- This topic was modified 8 months, 3 weeks ago by FrAnksch. Reason: format optimization
- This topic was modified 8 months, 3 weeks ago by Brendan. Reason: tagged code as code
- This topic was modified 8 months, 3 weeks ago by Brendan. Reason: tagged code as code
- This topic was modified 8 months, 3 weeks ago by Brendan.
- This topic was modified 8 months, 3 weeks ago by Brendan.
Attachments:
You must be logged in to view attached files.February 26, 2024 at 7:42 PM #50563
BrendanKeymasterThanks for posting this Frank. Sorry, I was trying to format the code part as code, but for some reason it wasn’t working. Not sure why. So if you were wondering why it looks like I was editing your message, that was all it was. I reverted back to the quote you used.
Not sure why the forum isn’t letting me tag code
function code() { // do some things }
-
AuthorPosts
Viewing 1 reply thread
You must be logged in to reply to this topic.