Programmatically set record color

Viewing 11 reply threads
  • Author
    Posts
  • August 29, 2019 at 9:44 PM #36607

    john cesta
    Participant

    Is there a way to programmatically set a record color?

    Like

    if today() == meetingDate
    Record set to Red

    August 30, 2019 at 12:19 AM #36613

    Brendan
    Keymaster

    Hi John,

    Not at the moment. But in the next update I’ve added a method called record.setRecordColor() which would let you do that by giving it a web colour in hex format. E.g. record.setRecordColor('#FF00CC'); It requires you use the Scripting engine though.

    Here’s an example I just tested:

    function Record_Colour_Script() {
    
    	var number = record.getFieldValue('fld-046db84197fd44a6adf50b3a9ab426d5');
    	var colourHex = '#005090';
    	if (number > 20) {
    		colourHex = '#c59';	
    	} else if (number == undefined) {
    		colourHex = 'CLEAR';
    	}
    	record.setRecordColor(colourHex);
    
    	form.saveAllChanges();
    	
    
    }
    
    Record_Colour_Script();

    It won’t work yet in the production Tap Forms version. But it will in the next update.

    August 30, 2019 at 6:10 AM #36626

    john cesta
    Participant

    Perfect, that could work.

    September 4, 2019 at 4:24 AM #36680

    matt coxon
    Participant

    hi Brendan, this would be excellent, will it be conditional, example .. I have a checkbox record field “hot list” I use this for the most important records within a form. Currently I select all “hot list” via a filter, and then manually mark all as red. (and when no longer in the hot list I have to manually de-select the color) Would be good if I can automate (via a script)

    thanks
    Matt

    September 4, 2019 at 4:31 AM #36681

    matt coxon
    Participant

    Sorry, just re-read your post, so answer is yes (I think) :-)

    thanks

    September 4, 2019 at 5:49 PM #36682

    Sam Moffatt
    Participant

    You would have a script field that is connected to the check box and then any time the checkbox state was toggled, it’d run the script and it could change the colour accordingly.

    For John’s original today() == meetingDate example, I think you would have to tell Tap Forms to re-evaluate the calculations once a day if using a field script or have a form script that you run once a day to scan and update the record colours.

    May 13, 2020 at 10:06 AM #40582

    Oliver Berger
    Participant

    Hi, I read through this and used the forum search (that’s how I found this thread, obviously).

    I’m looking for a way to color a field depending on what I entered. Let me give you an example:

    As I am in the process of developing a sci-fi roleplaying game I need a list of star ships with lots of game data. Let’s assume there are different manufacturers around in my universe.

    So if a starship is made by “Martian Weapon Systems” OR “MWS” I want the field “class” to be displayed in the color red.

    Obviously there already is another field “manufacturer” that I want to build the dependancy on.

    Any pointers?

    TIA
    Oliver

    May 13, 2020 at 11:34 AM #40587

    Brendan
    Keymaster

    Hi Oliver,

    Although you can colour fields and values in Tap Forms, they are global settings on the Field object itself. So any change made to them will apply to every record, not just for a particular record.

    But there is a labelColour and valueColour property on the Field object that can be accessed from a Script.

    Thanks,

    Brendan

    May 13, 2020 at 11:41 AM #40588

    Oliver Berger
    Participant

    Hej Brendan, thank you for the fast reply. Could you post an example of how to use those properties? At best in a way I can utilize it for my planned task.

    Thanks!

    Cheers, Oliver

    May 13, 2020 at 12:18 PM #40590

    Brendan
    Keymaster

    Sure… But like I said, it would apply to every record and not to just a specific record because it’s a field property and not a combined record/field property.

    function updateFieldColour() {
        var field = form.getFieldNamed('Notes');
        var topic_id = 'fld-d182d7483c3240b3bb06ea469dbf405c';
        var value = record.getFieldValue(topic_id);
        if (value == 'Some Value') {
            field.labelColour = '#c90000';
        } else {
            field.labelColour = '#000000';
        }
    
        form.saveAllChanges();
    };
    
    updateFieldColour();

    Hope that’s what you’re looking for.

    January 6, 2021 at 4:43 AM #43077

    Stephen
    Participant

    Hi, I’m looking to achieve something similar to this thread, using Bredan’s example above I have entered the following code, but I’m getting unpredictable results, plus my no colouring state is clearly not right!

    Outcome should be, checkbox field true, record red. Checkbox field false, record not coloured.

    So, for the time being I’ve set my no colour state to green, just so I can see a change. The script appears to give the correct result when triggering manually with the play button at the bottom of the list of scripts, but not running on change of value of the check box field.

    Any guidance appreciated!

    Stephen

    function Record_Colour_Script() {
    
    	var number = record.getFieldValue('fld-5b558c4b243d4d428355eec24dadfb66');
    	var colourHex = '#FF0000';
    	var clear = '#FFFFFF00';
    	if (number > 0) { record.setRecordColor(colourHex); record.setRecordColor(clear);
    	}	
    	form.saveAllChanges();
    	
    }
    
    	Record_Colour_Script();
    January 6, 2021 at 9:12 AM #43084

    Stephen
    Participant

    Ok, my bad…

    RTFM!

    The answer is here all along… Tap Forms Scripting 101.

    So there are two types of scripts… I had created mine in the wrong place. It is now made as a field script. So answered half of my own questions. D’oh!!

    Now, if I can just find out how to return the record colour to default appearance…
    I’ll keep looking until someone can chip in with a clue, maybe I’ll be back to solve my own issue again! lol

    Doing some serious learning today! ?

    Stephen.;)

    January 6, 2021 at 1:51 PM #43088

    Brendan
    Keymaster

    Hi Steven,

    To remove the colour value, just call record.setRecordColor(null);

    January 6, 2021 at 1:57 PM #43089

    Stephen
    Participant

    Hi Brendan,

    thank you.

    I am loving Tap Forms, I just wish I was better at it!

    Cheers, Stephen.

Viewing 11 reply threads

You must be logged in to reply to this topic.