Copy link to clipboard
Copied
I have some javascript that mostly works for me but have just one issue that should be simple. Basically I have a form set up like this:
DBB | DB | C+DBB | C+DB | |
Total Ranking Score | 300 | 200 | 400 | 50 |
Suggested Method | C+DB |
The way it works is it searches the number fields in the first table (each is named RankingScore.DBB, RankingScore.DB, etc. to put them in a group) for the one with the lowest number and then populates the name of that column using the tooltip from the same field (the tooltip has the same name as the column).
Here is the Javascript that I have in the Calculation for the SuggestedMethod field:
var oMinFld = null;
// This line gets all the fields in the "RankingScore" group and
// finds the one with the lowest value. It assumes all fields contain a valid value
this.getField("RankingScore").getArray().forEach(
function(oFld)
{
if(!oMinFld || (oFld.value < oMinFld.value))
oMinFld = oFld;
}
);
if(oMinFld)
event.value = oMinFld.userName; // this is the tooltip
else
event.value = "";
This works great. The problem is that each of the RankingScore fields is a calculation of data from elsewhere in the form and are initially set to calculate at 0 until the user starts entering in numbers in said other fields.
The problem is that the initially the name that shows in the SuggestedMethod box automatically populates with the column with the lowest number from the left. That means that even before it starts getting calculations it is set to DBB because all values are 0 (and that is the leftmost column). I'd like the box to remain blank until the calculations make those numbers higher than 0.
I belive that the current else statement would work if there were no calculations in the RankingScore group. I have tried to say something like this but it doesn't work.
if(oMinFld === 0) // or < 0.1
event.value = "";
else
event.value = oMinFld.userName; // this is the tooltip
Any suggestions on how to get the SuggestedMethod field to show up as blank when all the fields are 0?
Copy link to clipboard
Copied
Use this:
var oMinFld = null;
this.getField("RankingScore").getArray().forEach(
function(oFld)
{
if (oFld.value > 0 && (!oMinFld || (oFld.value < oMinFld.value)))
oMinFld = oFld;
}
);
if(oMinFld)
event.value = oMinFld.userName; // this is the tooltip
else
event.value = "";