Hi,
I'm trying to change the color of a single line text using scripting instead of the usual 'computed field' approach. Is this possible? My equivalent 'computed field' code looks like this;
CASE CHECKBOX_1
WHEN 0 THEN
CASE STATUS_1
WHEN 1 THEN '<span style="text-align:center; line-height:30px; color:green; background:green; width:50px; float:left; height:25px;">GRN</span>'
WHEN 2 THEN '<span style="text-align:center; line-height:30px; color:red; background:red; width:50px; float:left; height:25px;">RED</span>'
WHEN 3 THEN '<span style="text-align:center; line-height:30px; color:yellow; background:yellow; width:50px; float:left; height:25px;">YEL</span>'
WHEN 4 THEN '<span style="text-align:center; line-height:30px; color:blue; background:blue; width:50px; float:left; height:25px;">BLU</span>'
END
ELSE '<span style="text-align:center; line-height:30px; color:black; background:black; width:50px; float:left; height:25px;">BLA</span>'
END
This works, however, I have 20 or so fields to apply this logic to. It would be much simpler to manage using a behavior script to process this as a loop for CHECKBOX and STATUS 1-20.
Thanks for your help.
Solved! Go to Solution.
Solved by gasevsm. Go to Solution.
Thanks Martin,
I have the case and conditional aspects working, but can't get the HTML formatting to work. How do I deal with "escaping" characters? I'm not familiar with that.
Looking at just a part of the code...
var green = '<span style="text-align:center; line-height:30px; color:green; background:green; width:50px; float:left; height:25px;">GRN</span>';
item.FIELD = green;
When the script runs the resulting error is: "At least one of the input values was set to an illegal value."
Any suggestions on getting the HTML to be accepted and execute?
Here's a working example, Ty.
1. your field needs to be made into a non-computed field.
2. in your script use this format to set value for each case. eg.
item.TEST_FIELD_FORMATTING = '<span style=\"text-align:center;line-height:30px;color:red;background:red;width:50px;float:left;height:25px;\">RED</span>';
May be subtle to see, so what I did is:
- ecaped the double-quotes within the script by placing backslash in front of each them
- also removed all whitespaces from the string that is within those (now escaped) double quotes.
Yo ucould use this model and the JS switch/case statement to get it finished. I recommend always setting a switch() { default: } case as well to something recognizable - saves from tons of debugging if none of the case(s) match the expression you're switching on.
I should add, I tested on Chrome. Test the effect of this new javascript-driven formatting of field values in few browsers to see how each handles the HTML character escaping approach. I expect it'd be no problems but let me know if find any incosistency; more than happy to explore an alternate solution 😉
Cheers,
Hi Ty,
I used SLT field as well; I made sure to edit the field first to clear the computed formula and re-save the field. Only thereafter I used your original html formatting in a action script to make it work as per my example below. Let me know if its still not working after this; we might connect briefly offline to explore the solution together.
Can't find what you're looking for? Ask the community or share your knowledge.