sort records by table dates

Tagged: , ,

Viewing 1 reply thread
  • Author
    Posts
  • April 5, 2020 at 11:56 PM #40244

    Wolfgang
    Participant

    Is there a way to sort records by a table-field date? And if I have more than one event in the table, sorting the records by the newest date? The table itself is sorted in ascending order (the newest is last).
    I can imagine that’s a good job for a script! I can read and adapt scripts, but not so well at all in writing them ?. But maybe there is a standard way…

    April 6, 2020 at 2:05 AM #40248

    Brendan
    Keymaster

    You would definitely need a Script field for this.

    So you would want to return the first or last sub-record within the table field, depending on how you’re sorting it. Then you would set your parent form to sort by the Script field.

    Here’s a sample script:

    function getTableDateValue() {
    
    	var table_id = 'fld-c433974d87de4bbca4eae626bc412408';
    	var date_time_id = 'fld-56d1a49577574de1a229e66f1acaf676';
    	var table_records = record.getFieldValue(table_id);
    	var date_time;
    	
    	if (table_records.length > 0) {
    		var first_record = table_records[0];
    		var last_record = table_records[table_records.length - 1];
    		date_time = first_record.getFieldValue(date_time_id);
    	}
    	return date_time;
    }
    
    getTableDateValue();

    Either you return the first_record’s date_time value or the last_record’s date_time value depending on how your Table field records are sorted and if you want to get the minimum or maximum date value.

    Hope that gets you started. You’ll need to use your own field IDs of course.

    Brendan

Viewing 1 reply thread

You must be logged in to reply to this topic.