Ability to color rows in multi-columns?

Viewing 13 reply threads
  • Author
    Posts
  • June 11, 2020 at 3:21 AM #40880

    pierrot_rennes
    Participant

    Hi,

    Is it possible to colorize the lines in multicolumn mode according to a check box?
    A script?
    I have a collection and I would like the row of a record to be colored if the check box is activated for each record
    Or even better depending on a value 1 or 2 or 3 in a field, the color would be different
    Unless there is another solution?

    Attachments:
    You must be logged in to view attached files.
    June 11, 2020 at 10:25 PM #40895

    Sam Moffatt
    Participant

    You can use a script field to watch another field and set the record colour. Using the TV Shows template, here’s a script to watch a checkbox and set the field to green if checked or white if not:

    var completed = record.getFieldValue('fld-25c62d7db6004725910d926d8a7fd085');
    if (completed)
    {
    	record.setRecordColor('#00FF00');
    }
    else
    {
    	record.setRecordColor('#FFF');
    }

    Replace the hex colours with your own preferred colours and you can use a similar situation to check if it’s a given number and set the appropriate colouur.

    June 12, 2020 at 1:49 AM #40908

    pierrot_rennes
    Participant

    Hi,
    Thank you for the quick reply
    I will test

    June 12, 2020 at 2:04 AM #40909

    pierrot_rennes
    Participant

    Test but error script at line 13

    Attachments:
    You must be logged in to view attached files.
    June 12, 2020 at 7:32 AM #40920

    Daniel Leu
    Participant

    You need a closing curly bracket before Collection():

    function Collection() {
       var completed = record.getFieldValue('fld-25c62d7db6004725910d926d8a7fd085');
       if (completed)
       {
       	record.setRecordColor('#00FF00');
       }
       else
       {
       	record.setRecordColor('#FFF');
       }
    }
    
    Collection()
    June 12, 2020 at 11:00 AM #40924

    pierrot_rennes
    Participant

    Hi,
    Thanks for your help
    I made the wrong field in my initial request
    I want the line to change color when the check box in the Collection field is activated
    I tried to understand and adapt your code with the corresponding field but I have a script execution error (see in join)
    If you can help me
    Good night

    Attachments:
    You must be logged in to view attached files.
    June 12, 2020 at 11:28 AM #40926

    Daniel Leu
    Participant

    Use var collection = .... and not var collection_id = ....

    June 12, 2020 at 12:09 PM #40927

    pierrot_rennes
    Participant

    Hi,
    I tried but it doesn’t work
    At least not as it should
    Only the first line is blank (the collection field is not checked)
    But the lines with the collection field checked do not change to color (yellow)
    What I would like is that all the lines with the collection box activated automatically change color (see in join)
    Thanks

    Attachments:
    You must be logged in to view attached files.
    June 12, 2020 at 2:51 PM #40931

    Daniel Leu
    Participant

    Well, it fixes your syntax error, doesn’t it? Sorry, I was only commenting on that and not checking your code!

    You should add a form.saveAllChanges() at the end of the function to save the color changes.

    Following script works for me:

    function Script() {
    	var check_mark = record.getFieldValue('fld-906aa8b165cf42c0830fd79a460afe75');
    	if (check_mark) {
    		record.setRecordColor('#f00');
    	} else {
    		record.setRecordColor('#000');	
    	}
    	form.saveAllChanges();
    }
    
    Script();
    June 12, 2020 at 10:22 PM #40933

    Sam Moffatt
    Participant

    Good catch on the form.saveAllChanges(), should have put that in my original script. Seemed to work ok without it in the small testing I did though.

    June 13, 2020 at 12:39 AM #40936

    pierrot_rennes
    Participant

    Hi,
    Thank you both very much for your help, it works
    It is not automatic when I check the collection box, I have to trigger the script on each recording
    (see in join)
    Is there a possibility to make this automatic?
    good week-end

    Attachments:
    You must be logged in to view attached files.
    June 13, 2020 at 12:51 AM #40938

    Sam Moffatt
    Participant

    I think you’ve created a form script rather than a script field. Form scripts are created on the “Scripts” tab but “Field Scripts” are created like normal fields with the type “Script”. Script fields should monitor the state of the fields they reference and auto update when those fields change. Just copy the working form script and put it into a new script field.

    June 14, 2020 at 6:15 AM #40950

    pierrot_rennes
    Participant

    Hi Sam,

    It’s done, thanks a lot !!!
    If I want to color certain lines in relation to two fields to check, I can put everything in the same script I think?
    (with different colors of course ;-))

    June 14, 2020 at 1:27 PM #40953

    Sam Moffatt
    Participant

    Yeah, use a single script with all of the logic in it, you can pull in as many fields as you like and they’ll all trigger the script. You can then pass it through which ever conditionals you want in the Javascript code to set the row colour.

    I would advise against having multiple script fields for setting the row colour because then the logic for the row colour is in two places and debugging that is a nightmare to fix :)

Viewing 13 reply threads

You must be logged in to reply to this topic.