Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Script not updating automatically
- This topic has 2 replies, 2 voices, and was last updated 4 weeks ago by
Stuart Barry.
-
AuthorPosts
-
February 1, 2025 at 11:31 AM #51603
Stuart BarryParticipantI have created a script that works to change the colour of the record conditionally. I initially created it as a form script and can run it or use a shortcut and it does what it is supposed to do. I tried the same script on a field because I want it to activate automatically as soon as a new record is added or an existing one changed. Although the script works when I run it manually on the field it does not automatically activate when the reference field is modified.
The first line of code (var type_id = record.getFieldValue (‘fld-631813d9eff54787894020691031bc77’);) references the field and gets the data successfully.
Any suggestions?
February 9, 2025 at 9:43 PM #51626
BrendanKeymasterSo you’re changing the value of your
fld-631813d9eff54787894020691031bc77
field? That should trigger the script to run. Put in a console log to see if that solves the problem. Also don’t forget to callform.saveAllChanges()
to commit the change to the database. That generally triggers a refresh of the display.March 5, 2025 at 10:11 AM #51693
Stuart BarryParticipantI already had the save command and console log. The type-id field is picked up correctly by the colour only changes when I run the script manually. I’d like it to run automatically on changing the colour field using the drop down box. Script shown below.
function Change_record_colour() {
var type_id = record.getFieldValue (‘fld-631813d9eff54787894020691031bc77’);
var red_col = “#ffbac6”;
var white_col = “#caffd4”;
var sweet_col = “#fef3a4”;
var fort_col = “#fdbb9c”;
var spark_col = “#a3ff79”;
var rose_col = “#f4d8dd”;console.log(type_id);
if (type_id == “Red”)
{record.setRecordColor(red_col);}if (type_id == “White”)
{record.setRecordColor(white_col);}if (type_id == “Sparkling”)
{record.setRecordColor(spark_col);}if (type_id == “Sweet”)
{record.setRecordColor(sweet_col);}if (type_id == “Fortified”)
{record.setRecordColor(fort_col);}if (type_id == “Rosé”)
{record.setRecordColor(rose_col);}form.saveAllChanges();
}
Change_record_colour();
-
AuthorPosts
You must be logged in to reply to this topic.