Ok, well this kind of works, but it’s not great:
function Script() {
var first_name = record.getFieldValue('fld-b955dffe477c494db26f60faf1dd9a75');
var parent_field_id = 'fld-208116bc2576460da36cee99b12e3c04';
var parent_field_value = record.parentRecord.getFieldValue(parent_field_id);
return parent_field_value;
}
Script();
In this form I have a Table field with 3 fields in it. A First Name field and a Last Name field and a Script field.
The first line to get the field value from the Table field’s record is only there to trigger the script to execute when the First Name field is modified. It’s not doing anything with the value.
The trick is record.parentRecord.getFieldValue(parent_field_id);
But Tap Forms won’t trigger the Script field to execute if you modify the parent form’s field. I think that’s probably why I didn’t document this. The parent form would have to loop through all Table fields looking for scripts that reference the parent form’s field and then execute the scripts. Just hadn’t really flushed the coding out for that I guess.
Can you share the script you are using or a test case to reproduce this?
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Hello,
since the last Tap Forms update, the import from CSV files with the PapaParse script leads from short dates dd.MM.22 to dd.MM.1922. For example, the German date 12.04.22 becomes 12.04.1922 on import. It should be 12.04.2022. That wasn’t a problem in the last version.
Does anyone have an idea to solve this issue without splitting the date and adding 100 to the year? This would lead to an error if the year in the date is really 19xx.
e.g.:
...
let datum_string = line[0];
let datum = parseDate(datum_string);
let conv_date = new Date(datum.getFullYear() + 100, datum.getMonth(), datum.getDate());
...
BTW: Copy&Pasting the short date from the CSV file to the date field works fine.
Thanks in advance.
Chris
-
This topic was modified 3 years, 9 months ago by
Chris Ju.
-
This topic was modified 3 years, 9 months ago by
Chris Ju.
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.
Thank you for sharing your form template. When you use record in a field script inside a table, you are referring to that row in the table and not the overall record anymore.
I don’t think that there is a way to get to the main record from the table field script. How about moving the intensity calculation to the main record and update the table’s intensity field from there?
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
AnonymousInactive
Thank you.
The table has 4 columns, Set, Reps, Weight and Target Weight and the Id of the table is fld-f59e078819e24d2aa1492d36d8fe268c.
The situation is the following:
1. The form contains a field F that is not a table and a field that is the table T.
2. The table T contains a column T_s of type script.
3. For any given record I want to have access to the value of field F inside the script that pertains to T_s.
If I run the following code inside T_s’ script (fld-f59e078819e24d2aa1492d36d8fe268c is the Id of the table)
var table_field_id = 'fld-f59e078819e24d2aa1492d36d8fe268c';
var testrecords = record.getFieldValue(table_field_id);
console.log(testrecords.length);
var testvalues = record.values;
console.log(testvalues.length);
I get the output:
11.04.22, 18:44:59 / Sets Old / Target Weight
0
undefined
I’am new to Tap Forms 5. Maybe missing some fundamental stuff here?
Cheers
AnonymousInactive
Hello everybody,
I like to access the record of a Form F that has a table field T from inside a script field inside T. If I use record.values I get a dictionary of the form
{"Id of table field 1" = value of table field 1;
"Id of table field 2" = value of table field 2; … }
.
But I need to access the value of a specific field of F from inside the script field of the table field T, i.e I need a dictionary of the form
{"Id of field 1 of F": value of field 1 of F;
"Id of field 2 of F": value of field 2 of F; …}
.
Is this possible?
Cheers
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
Hi Juan,
This does not require a script for that (since you posted in the Script Talk forum). You can just go to the Options tab on the Print panel and turn off the date, time and page number options.
Thanks!
Brendan
I forget that dealing with dates in JS is so weird at times, I went looking and found a decent looking strftime port and threw it in my script manager repo as well.
Sam again,
After having explored a bit further, this is the situation:
The script Kalva works fine with 2 of the breeding bulls (1 & 4)
It doesnt work with 3 (the rest) of the breeding bulls (1, 3 & 5)
I then get the message in MAC “Varning Det gick inte att hitta posten!”
I cant figure out why some bulls work and not the others.
Sam The problem is not the non parity.
The problem is that fader-ID is not shown after running the script Kalva.
The message “Script is run complete” I received in IOS.
When running in Mac I received “Fel! Sätta grupprekordet”
Hi again,
The script Kalva, created by Sam Moffatt, worked very well a couple of weeks ago.
Now when I have to use it because calves are started coming the calfs father in the form Kalvningar is not shown.
I get “Script is run complete” instead of “Gjord”
Enclose template.
Sorry about this.
Stig
Attachments:
You must be
logged in to view attached files.
Javascript date handling is a bit confusing:
The getDay() method returns the day of the week for the specified date according to local time, where 0 represents Sunday.
The getMonth() method returns the month in the specified date according to local time, as a zero-based value (where zero indicates the first month of the year).
What you want to use is something like this:
var drDay = sessionDate.getDate();
var drMonth = sessionDate.getMonth() + 1;
var drYear = sessionDate.getFullYear();
-
This reply was modified 3 years, 10 months ago by
Daniel Leu.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks