Table field type

Viewing 7 reply threads
  • Author
    Posts
  • November 14, 2019 at 1:21 PM #38046

    Stephen Abshire
    Participant

    Greetings,

    Does anyone have some sample code on how to access rows of data that are contained within a ‘table’ field type? Specifically, I would like to programmatically create columns, read & modify the values of the cells.

    Also, will this method work to access the tables that contain the data from linked forms in a one-to-many relationship?

    November 14, 2019 at 3:16 PM #38049

    Stephen Abshire
    Participant

    Actually got this one working.

    November 14, 2019 at 5:54 PM #38050

    Brendan
    Keymaster

    Hi Stephen,

    I’m assuming you found the Child Records Loop snippet? That will write the code for you to loop through the records of a Table field or a Link to Form field.

    This is the basic code that Tap Forms writes for you when you double-click on the Child Records Loop snippet when you have a linked field selected:

    function recordsLoop() {
    
    	var client_call_log_id = 'fld-01144d1c706e4007a7ad1a7c98fe9147';
    	var topic_id = 'fld-e67b43da03a24c66a018ae657c9d6b1f';
    	var client_call_log = record.getFieldValue(client_call_log_id);
    
    	for (var index = 0, count = client_call_log.length; index < count; index++){
         	var topic = client_call_log[index].getFieldValue(topic_id);
    		if (topic) {
    			// do something
    		}
    	}
    	return;
    }
    
    recordsLoop();

    Thanks,

    Brendan

    November 14, 2019 at 7:54 PM #38051

    Stephen Abshire
    Participant

    Greetings,

    Yes I was able to get things working but it did bring up a new question. Contained within my field of type ‘table’ I have a child field of type ‘checkmark’. The question is how do I respond to the click event (if this exists) so that I can run a script?

    Currently the table is giving me a sum of one of the numeric child fields which is usually great. What I need to do is a SUMIF so that a given row in the table is added to the total only if its checkmark field is checked. I am okay if I need to write a script to do the math but I don’t know where to put the script so that it responds to the checkmark click event. I would rather automate this if I can and not be required to manually fire a form level script.

    November 14, 2019 at 8:28 PM #38053

    Brendan
    Keymaster

    Table fields are sort of like forms themselves, but they don’t belong to any actual form. So you can’t write a Form Script attached to a Table Field.

    But what you can do is add a Script Field to your Table Field that checks the value of your Checkmark field and returns a sum if the Checkmark field returns 1. 1 is On, 0 is Off.

    Then you could simply tell Tap Forms to total up the result of your Script Field which will give you the grand total of only the checked items.

    November 15, 2019 at 8:45 AM #38059

    Stephen Abshire
    Participant

    That worked perfectly so one more follow-up question. Can I through script or calculation field access the auto sums/totals that the table creates for me? I need that value to feed another script on my form.

    November 15, 2019 at 8:36 PM #38062

    Brendan
    Keymaster

    From a script you can call form.getTotalOfField(field_id) to get the grand total value. There’s also an equivalent one for saved searches: `search.getTotalOfField(field_id)’

    However, it wouldn’t work for a Table field. I guess I need to add those functions to the Table field. You’d just have to write a script that loops through the records and totals the value of the sub-field and displays it on the parent form.

    However again, the Calculation field does have the ability to give you the total of a field from within a Table field. Just double-click on any numeric type field in your Table field on the formula editor and Tap Forms should print something out like TOTAL::Table Field::Sub-Field. That’ll give you the result you want.

    November 18, 2019 at 5:35 AM #38078

    Stephen Abshire
    Participant

    Got it working just wrote a script for it.

Viewing 7 reply threads

You must be logged in to reply to this topic.