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)
This makes me think of a serialization error, where the api sends invalid json to the client. You can quickly verify this by inspecting the preview tab of GetNextQuerySessionPage, if it can be expanded properly or bot (chromium can't deal with invalid json in the preview tab either). To see what part is invalid, you can copy the raw response string from the response tab and pass it through a json validator of your choice. I expect something like NaN or Infinity to be present in there, those are numeric values that are not valid json.
If that's the case, you can adjust the custom operator to avoid such values, by for instance not dividing by zero.
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}%");
}
}