Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › automated run of field script with boolean field
Tagged: automatic boolean
- This topic has 3 replies, 2 voices, and was last updated 9 months ago by Giovanni Vittoria.
-
AuthorPosts
-
February 17, 2024 at 1:16 AM #50502
Giovanni VittoriaParticipantHi,
first if all: I’m a absolute rookie in terms of scripting, so SORRY for the bad code & for my stupid questions. But I’m willing to learn ;-)
I have 2 date fields and want them to show the date when a boolean field (checkbox) was checked or unchecked.
Within the form I use a script-field with the script below.The code is not nice, but it works in general. But only if the entry is manually refreshed (iOS: pull down).
Other tests with website-field (according to https://www.tapforms.com/forums/topic/pre-processing-field-entry/) work automatically when the entry is stored.
I would like to have my script running as soon as the checkbox is checked or unchecked.Could anybody please optimize my code or help me to get this work?
Thanks!
function Checkdate() {
var check_field_id = “fld-abc”;
var date_field1_id = “fld-xyz”;
var date_field2_id = “fld-zyx”;var check_value = record.getFieldValue(check_field_id);
var date1_value = record.getFieldValue(date_field1_id);
var date2_value = record.getFieldValue(date_field2_id);if (check_value == 1)
{
if (date1_value == null)
{
record.setFieldValue(date_field1_id, new Date());
record.setFieldValue(date_field2_id, null);
}
}
else
{
if (date2_value == null)
{
record.setFieldValue(date_field2_id, new Date());
record.setFieldValue(date_field1_id, null);
}
}
form.saveAllChanges();}
Checkdate();
cheers, Giovanni
February 17, 2024 at 11:57 AM #50509
Daniel LeuParticipantI do think that the script runs as you expect it to run, but the issue is related to displaying the updated results. You could check that the script runs by adding a return value or putting something in the console.
I’ve seen this before that TapForms doesn’t display updated fields. Unfortunately, the only solution is the one you’re using :-(
February 18, 2024 at 12:37 AM #50511
Giovanni VittoriaParticipantThank you Daniel!
I checked this and you”re absolutely right:
the script IS working, but the updated results are not displayed correctly on my iPhone. The temporarily arranged return value appears in the script field.
The date fields are displayed correctly as soon as I go back to the entry list and back to a single entry, even without manual refresh (I am on iPhone).
On my iPad (with list view on the lefthand side) it is clearly visible, that the date fields are updated as soon the checkbox is changed.
So everything is Ok for me.
Thanks for opening my eyes! ;-)- This reply was modified 9 months ago by Giovanni Vittoria.
cheers, Giovanni
February 18, 2024 at 2:45 AM #50513
Giovanni VittoriaParticipant[EDIT]
deleted(since incorrect due to dependencies)
- This reply was modified 9 months ago by Giovanni Vittoria.
- This reply was modified 9 months ago by Giovanni Vittoria.
cheers, Giovanni
-
AuthorPosts
You must be logged in to reply to this topic.