Concatenating text fields from multiple records

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Using Tap Forms Concatenating text fields from multiple records

Viewing 2 reply threads
  • Author
    Posts
  • May 30, 2019 at 5:02 PM #34966

    FourD
    Participant

    In a Join link type of a relationship between two forms, how would one concatenate the multiple values of the text fields in the child form into a single text string and deposit the result to the related text field (not the linking field) in the parent form?

    Is this possible?

    Here’s a simplified design and example.

    The design of the Parent Form:

    Field X (a number field whose value is unique in each record)

    Field Y (a Link to Form field linked to the child form with a Join relationship where values from Field X match values of Field A in the the child form)

    Field Z, a field to be created by concatenating values of in the Child field B of the related records in the Child form.

    The Design of the Child form has is as follows:

    The child form has the following fields:

    Field A, a number field that matches values of X in the parent form

    Field B, a text field

    There are one or more records that share the same value for A.

    Let’s say there are three records in the Child form with A=15. The values for B are:
    dez
    sim
    vid

    I want to create the string “dez,sim,vid” and replace the contents of Field Z in the Parent form.

    June 1, 2019 at 1:51 AM #34978

    Brendan
    Keymaster

    Hi FourD,

    Sorry for my delay in replying. I just saw your post today.

    You can certainly do this with a Script field. You can ask for the array of records from a Link to Form field and then get the values from the field you’re interested in, then concatenate them together.

    June 1, 2019 at 10:29 AM #34992

    Sam Moffatt
    Participant

    I use this script in a script field to materialise the child values into the parent field to make it searchable:

    function recordsLoop() {
       var retval = [];
    	var shipments = record.getFieldValue('fld-db2fcdb4d79c466ea09671c47d2ae645');
    	for (var index = 0, count = shipments.length; index < count; index++){
         	var tracking_number = shipments[index].getFieldValue('fld-7a29242731d9451092c92d8586dbc94a');
    
    		if (tracking_number) {
    			retval.push(tracking_number);
    		}
    	}
    	return retval.join(' ');
    }
    
    recordsLoop();
    

    fld-db2fcdb4d79c466ea09671c47d2ae645 is a Link to Form field pointing to the child records (shipping entries in this case) and fld-7a29242731d9451092c92d8586dbc94a is the tracking number in that shipping record.

    When you’re in the Script Editor for the script field, use the “records loop” snippet on the “Link to Form” field to get most of this boilerplate handled for you.

Viewing 2 reply threads

You must be logged in to reply to this topic.