Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Example of using record.getMaxOfLinkedFieldForField(linkedFieldID, fieldID);
- This topic has 6 replies, 3 voices, and was last updated 2 years, 2 months ago by dan carter.
-
AuthorPosts
-
September 25, 2022 at 3:37 PM #47997
dan carterParticipantHello,
I have a parent form called Clients and child form with a number field called Target. I’d like to use record.getMaxOfLinkedFieldForField(linkedFieldID, fieldID); to find the max of Target for each particular client.
I’ve tried using different field ids in the linkedFieldID and fieldID positions and the the script will run without errors but no output is produced.
Are others having success with this?
Kind Regards, Dan
September 25, 2022 at 5:41 PM #47999
Daniel LeuParticipantDo you mind to share your script?
September 25, 2022 at 5:52 PM #48000
dan carterParticipantMany thanks for looking Daniel. You’ll also see some comment out lines I’ve tried.
var date_id = ‘fld-b5cc9a209ab94005862f111287a1c6e8’;
var target_id = ‘fld-d984603583864e5fb5af42de33ff177d’;
var change_id = ‘fld-3f28cc416bf34e9fbe70122e65fb8d22’;
var last_first_id = ‘fld-b052524e3f814d909bdc1256d5153f51’;
//var client_id = ‘fld-cb862ea49ea64d7c8f8fbdbf6cabd80c’;
var min_target = record.getMinOfLinkedFieldForField(target_id, last_first_id);
var max_target = record.getMaxOfLinkedFieldForField(target_id, last_first_id);
//var max_lc_total = record.getMaxOfLinkedFieldForField(target_lc_id, client_id);
var copyOfRecord = record.duplicate();
record.setFieldValue(date_id, new Date());
record.setFieldValue(change_id, (max_target / min_target)-1);
document.saveAllChanges();Utils.alertWithMessage(‘Script Run Complete!’, ‘Cool!!!!!’);
September 25, 2022 at 6:52 PM #48001
Daniel LeuParticipantHmmm… I expected to see a
Field Script
like this:var target_id = ‘fld-d984603583864e5fb5af42de33ff177d’; var last_first_id = ‘fld-b052524e3f814d909bdc1256d5153f51’; record.getMinOfLinkedFieldForField(target_id, last_first_id);
But for your
Form Script
, I would check if the values you get are correct:console.log("min target: " + min_target); console.log("max target: " + max_target);
I don’t see why you create duplicate a record and then don’t use it.
September 26, 2022 at 1:21 AM #48006
BrendanKeymasterHi Dan,
If you export your form template (.tff) and post it here, we can look at it and see what’s going wrong with your script.
Thanks,
Brendan
September 26, 2022 at 1:24 PM #48009
dan carterParticipantThank you for the idea Daniel. This application will be used only on an iPad. Unfortunately when I use field scripts they prevent my form scripts from working.
My console.log returns “0” for min and max target.
I will upload my form template as per Brandon. I’m sure I’m missing something simple.
September 26, 2022 at 3:36 PM #48010
dan carterParticipantHere are the 2 involved forms. Clients and Leg Curl. A client will eventually have many Leg Curl records with varying Target amounts. I would like getMax… and getMin… functions to display least and most Target amount, as well as, percent Change. The Duplicate Exercise script is where I attempt, unsuccessfully, to do this.
This DB is being developed on and for an iPad.
Thank you for having a look, Dan
- This reply was modified 2 years, 2 months ago by dan carter.
Attachments:
You must be logged in to view attached files. -
AuthorPosts
You must be logged in to reply to this topic.