Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Using script to set record colour
- This topic has 3 replies, 3 voices, and was last updated 3 years, 11 months ago by Brendan.
-
AuthorPosts
-
December 30, 2020 at 7:49 AM #43014
Philip JonesParticipantHello all,
I am trying to follow Brendan’s instructions here: https://www.tapforms.com/forums/topic/programmatically-set-record-color/
By using the following code:
function Change_Record_Colour() { var ffs = record.getFieldValue('fld-c629f095416d4df5be8e1a7de4fd81ba'); if (ffs) { record.setRecordColor = '#ff0000'; console.log("red"); } else { record.setRecordColor = '#ffffff'; console.log("white"); } form.saveAllChanges(); } Change_Record_Colour();
But it is not actually changing my record colour.
The console is recording the correct values, so I know my *if* conditions are working OK.
I am able to change the record colour using the colour picker at the bottom of the record, just to the left of the refresh arrow icon and the size of the record in KB.
Am I doing something wrong?
Thanks,
Phil
December 30, 2020 at 8:05 AM #43015
Chris JuParticipantHere is an example (with german words), which works for me:
function Record_Colour_Script() { var erledigt_id = record.getFieldValue('fld-0f62df9131e64cdeae7b1a98580e700b'); var aufgehoben_id = record.getFieldValue('fld-f7738e96b4154742965b96ea5c697e31'); var gestrichen_id = record.getFieldValue('fld-a108b72455cb4fc8aa6354646e01fe1b'); var nicht_abrechenbar_id = record.getFieldValue('fld-5b27768928a3423ebddd542e3e05823f'); var abgerechnet_id = record.getFieldValue('fld-db41b041736543c697fc78671b0f2777'); if ((aufgehoben_id == true) || (gestrichen_id == true)) { colourHex = '#9D9D9D'; // rot } else { if ((erledigt_id == true) && (abgerechnet_id == false) && (nicht_abrechenbar_id == false)) { colourHex = '#ff9933'; // orange } else { if ((erledigt_id == true) && ((nicht_abrechenbar_id == true) || (abgerechnet_id == true))) { colourHex = '#008000'; // grĂ¼n } else { colourHex = '#ffff66'; // gelb } } } record.setRecordColor(colourHex); form.saveAllChanges(); } Record_Colour_Script();
December 30, 2020 at 8:24 AM #43016
Philip JonesParticipantThank you!
I realize now my mistake, as what I wrote to set the colour was incorrect.
record.setRecordColor = '#ffffff';
should have been
record.setRecordColor('#ffffff');
Thanks again. Now it works. I appreciate the help.
December 30, 2020 at 4:18 PM #43022
BrendanKeymasterYou can also do
record.recordColourHex = '#ffffff';
The
setRecordColor()
function was just an Americanization of the spelling ofcolour
. All that method does internally is sets the property as above. I just never published it. -
AuthorPosts
You must be logged in to reply to this topic.