Get Latest Date from Linked Form – No Script

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Using Tap Forms Get Latest Date from Linked Form – No Script

Viewing 1 reply thread
  • Author
    Posts
  • April 8, 2022 at 12:01 PM #47070

    Bernie McGuire
    Participant

    This is such a basic question, Im sure it’s been asked but I can not find the answer.
    For Example Main Form is a Customer
    Linke form is list of orders

    I want to show the latest order date, from the order form , on the Parent Customer Form. So I can see it on the Record list for the Customers.

    Oh, yes. I am using a JOIN relationship which is working perfectly.

    I can not find a way to get the ‘MAX’ date in a Calculated field. I prefer to not use scripting .

    I am using IOS (I do have Mac also)

    Please any help is appreciated.
    THanks Bernie

    April 11, 2022 at 11:21 PM #47084

    Brendan
    Keymaster

    Hi Bernie,

    You would have to use a Script for this function.

    There’s a function designed for getting the maximum value, but it only works for Number fields right now:

    var max_value = record.getMaxOfLinkedFieldForField(linkedFieldID, fieldID);

    But you could loop through the linked records manually and pick out the largest date value.

    Sorry it can’t be done with a Calculation field though.

    Here’s an example script that would do what you want:

    function getMaxDate() {
    
    	var orders_id = 'fld-41443e967b3c4bdd8e258eabef7ffc8c';
    	var date_id = 'fld-3604363a4c07424294113852f4b3651e';
    	
    	var orders = record.getFieldValue(orders_id);
    
    	var largest_date;
    	
    	for (var index = 0, count = orders.length; index < count; index++){
         	var date = orders[index].getFieldValue(date_id);
         	
    		if (date) {
    			// do something
    			if (largest_date == undefined || largest_date.getTime() < date.getTime()) {
    				largest_date = date;
    			}
    		}
    	}
    	
    	return largest_date;
    }
    
    getMaxDate();

    You would need to replace the fld-.... parts with the field IDs of your own fields though.

Viewing 1 reply thread

You must be logged in to reply to this topic.