Conditional Field Color

Hi all,

I want to set the foreground color of a row’s field in a foundset based on a value.

Code so far:

var vAge = plugins.dialogs.showQuestionDialog(‘Aging’, ‘Please select aging term in days. Serial numbers for items \nopen longer than the period selected will appear in red.’, ‘10’, ‘15’, ‘20’, ‘Cancel’);
if (vAge == ‘Cancel’)//Exit method
{
return;
}
var vDate = utils.dateFormat(new Date(2006,10,10),‘MM-dd-yyyy HH:mm:ss’);// Put date specified into date format. Months start at 0!

controller.find();
text1 = ‘#imported’;// # ignores case
date1 = ‘>’ + vDate + ‘|MM-dd-yyyy’;
controller.search();

if (databaseManager.getFoundSetCount(foundset) == 0)
{
application.beep();
plugins.dialogs.showInfoDialog(‘Find Result’, ‘No records were found.’, ‘OK’);
return;
}

//Loop thru foundset evaluating dates
var vMax = controller.getMaxRecordIndex();//Get number in foundset

for (row = 1; row <= vMax; row++)
{
controller.setSelectedIndex(row);//Go to row one

//Calculate difference in days
var vToday = new Date(2006,10,30);//Leave formatted as ‘Thu Nov 30 00:00:00 PST 2006’
var vDate = date1;
var vDifference = 0;//Difference between Today and Date data
vDifference = vToday - vDate;

var vDays = 0;//Difference expressed in days
vDays = Math.round(vDifference/(10006060*24));
//divide by number of milliseconds in a day and round off

if (vDays > vAge)//Difference versus dialog selection
{
//Set / Get foreground color
elements.text3.fgcolor = ‘#ff3333’;
text3 = ‘Red’;
var vColor = elements.text3.fgcolor;
application.output(row + ’ ’ + vDays + ’ ’ + vColor + ’ ’ + text3);

}
else
{
//Set / Get foreground color
elements.text3.fgcolor = ‘#000000’;
text3 = ‘Black’;
var vColor = elements.text3.fgcolor;
application.output(row + ’ ’ + vDays + ’ ’ + vColor + ’ ’ + text3);
}
}

Application Output =

1 19 #ff3333 Red
2 18 #ff3333 Red
3 17 #ff3333 Red
4 16 #ff3333 Red
5 15 #000000 Black

It looks like each specific field’s color has been set, but the column takes on the color of the last field processed. i.e. the column is either all red or all black. What am I missing?

I have not examined your script but I see one thing and think the other:

  1. I would jump out of the script when you found a matching condition. You can jump out by either setting a return at the end of the condition or add else statements so the rest of the script is skipped.
  2. There probably is some stuff in there that is equal to all conditions you are searching for. It is for that that you need 1.

Hope this helps,

Are you talking about applying a fgcolor to a field in 1 row of a list or table view?

ie Row 10, column 2 is red whereas all the other rows, column 2 is black?

If so you cant do it as the fgcolor for all the fields in that column will take on the conditional colour of the currently selected record.

I believe that this is a current lmitation with servoy.

Now that I look at it. I thought you ware talking about a row background color. Dexadrine is right about the limit for element settings. They are more or less generic’.

My intent was to change the foreground color of a field in a row where the elapsed time for that record exceded a limit. Could be rows 1, 3, 10, etc. of a found set.

Got it. Used the Filemaker technique of overlapping a transparent “display” field whose foreground is red. If condition is met, “display” is set to display the data (in red), else its set empty and the black text shows through. Clunky, but works.

Hmm… why so difficult?

var c = '#00000' // black
if (myImportantField == myCriteria )
{
	c = '#FF000'; // red
}
return '<html><font color="' + c + '">' + myImportantValue + '</font></html>';

Place that in a calculation and use a label or field with displayType set to HTML_AREA to display this and you are set.

Or am I oversimplifying things here…