Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Using Tap Forms › Get Latest Date from Linked Form – No Script
- This topic has 7 replies, 4 voices, and was last updated 4 months, 1 week ago by
Daniel Leu.
-
AuthorPosts
-
April 8, 2022 at 12:01 PM #47070
Bernie McGuireParticipantThis 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 ordersI 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 BernieApril 11, 2022 at 11:21 PM #47084
BrendanKeymasterHi 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.May 1, 2024 at 4:09 PM #50717
Shelby BufkinParticipantBrendan if (largest_date == undefined || largest_date.getTime() < date.getTime()) {
What do we put her at undefined to return largest date?
May 1, 2024 at 4:38 PM #50718
Shelby BufkinParticipantfunction LastDeliveryDate() {
var wellprodid = ‘fld-e5cb08e10b2c4f5ba277f18ad72b4ebd’;
var date_id = ‘fld-6700311b49074f97969c8a3780d63935’;var delivery = record.getFieldValue(wellprodid);
var largest_date;
for (var index = 0, count = delivery.length; index < count; index++){
var date = deilvery[index].getFieldValue(date_id);if (date) {
// do something
if (largest_date == undefined || largest_date.getTime() < date.getTime()) {
largest_date = date;
}
}
}return largest_date;
}LastDeliveryDate();
This is returning
5/1/24, 6:37:16 PM / Delivery Chemicals / LastDeliveryDate
LastDeliveryDate: TypeError: undefined is not an object (evaluating ‘delivery.length’), line:(null)
May 1, 2024 at 5:54 PM #50719
BrendanKeymasterCan you post your form template?
Is
wellprodid
a Link to Form field?May 2, 2024 at 10:36 AM #50720
Shelby BufkinParticipantYes I am I am joining Delivery Chemicals to Delivery form with a Join WellProdId=WellProd. This will pull all deliveries to that location but I want to pull the last delivery date and the amount of gallons delivered at that time.
Attachments:
You must be logged in to view attached files.May 2, 2024 at 7:25 PM #50722
BrendanKeymasteroops. I don’t have the password to unlock the form.
But also, try removing the
.getTime()
fromlargest_date.getTime()
anddate.getTime()
.May 3, 2024 at 8:10 AM #50723
Daniel LeuParticipantTo me, it looks like
var delivery = record.getFieldValue(wellprodid);
doesn’t return any records. Iswellprodid
correctly set? -
AuthorPosts
You must be logged in to reply to this topic.