I've been working on a custom operator to calculate a percentage from two numeric parameters.
It works fine when I test it with client test tool.
But when I try to use it a dashboard itself, it fails with the following error:
By looking to the Browser Developer tools, I don't see any error in the Network tab.
Can you please advise on how can I investigate and resolve this?
I've been using this custom operator: SkylineCommunications/SLC-GQIO-PercentageCalculation: Custom operator that allows the user to calculate a percentage for 2 columns. (github.com)
Hi Bruno,
I remember I saw a similar issue in the past, and if I recall correctly, it was related to an empty cell in one of columns that are used as argument for the custom operator. In order to avoid this issue, you could use the method TryGetValue available from 10.3.4 that will allow you to safely get the cell value. Below a snippet of the updated method HandleRow where the cell value is validated before to perform any calculation:
public void HandleRow(GQIEditableRow row)
{
//var firstValue = row.GetValue<double>(_firstColumn);
//var secondValue = row.GetValue<double>(_secondColumn);double dFirstValue;
double dSecondValue;if (!row.TryGetValue(_firstColumn, out dFirstValue))
{
row.Delete();
return;
}if (!row.TryGetValue(_secondColumn, out dSecondValue))
{
row.Delete();
return;
}if (dSecondValue == 0)
{
var result = -1;
row.SetValue(_newColumn, result, $"{result}%");
}
else
{
var result = (dFirstValue / dSecondValue) * 100;
var resultRounded = Math.Round(result, 2);
row.SetValue(_newColumn, result, $"{resultRounded}%");
}
}