Latest Date

Viewing 5 reply threads
  • Author
    Posts
  • January 31, 2021 at 9:08 PM #43346

    Martha Montgomery
    Participant

    New to Tapforms and trying to add a field for the latest date. I have tried using Maximum on the date field, but the result is not what I expect. The calculation is automatically filling in “Count”. The fields are joined in the two forms. In the pdf attached, I have included the field setup, calculation and the results…it is showing the date of Dec 31 1969 instead of Sep 30, 2020.

    I also tried to change “Count” to “Max”, but it will not let me.

    Any suggestions are appreciated.

    Attachments:
    You must be logged in to view attached files.
    February 2, 2021 at 5:02 PM #43353

    T.L. Ford
    Participant

    A script field would work.

    var when_id = 'fld-a13ae3e64dd340138d08e719fe2a9aa9';
    var childform_id = 'fld-8ead2e10d2634bd4925175d72f943857';
    
    function Max() {
    
    	var arr = record.getFieldValue(childform_id);
    
    	arr.sort(compare);
    	
    	return arr[0].getFieldValue(when_id);
    }
    	
    function compare(a, b) {
    
      if (a.getFieldValue(when_id) > b.getFieldValue(when_id)) {
        return -1;
      } else if (b.getFieldValue(when_id) > a.getFieldValue(when_id)) {
    	  return 1;
      }
      return 0;
    }
    
    Max();

    You will need to get your field ID’s.
    Make sure you set the return results type to Date.

    February 2, 2021 at 9:08 PM #43354

    Martha Montgomery
    Participant

    Thanks so much. I will give this a try.

    February 3, 2021 at 4:29 PM #43360

    Martha Montgomery
    Participant

    I am so very excited! I could not get this to work at first due to my limited knowledge, but after watching a couple of Sam Moffitt’s YouTubes and retrying to make sure I was picking the right fields, I got it to work. Thanks so very much!!!!

    February 3, 2021 at 5:00 PM #43361

    T.L. Ford
    Participant

    That’s awesome! I’m so glad!

    The scripting is powerful, but it also has a fairly steep learning curve. I have an intro to scripting here: http://cattail.nu/tap_forms/tap_forms_scripting_101/index.html

    – T

    February 3, 2021 at 5:04 PM #43362

    Martha Montgomery
    Participant

    Thanks for the link! I am definitely going to review it.

Viewing 5 reply threads

You must be logged in to reply to this topic.