Javascript function is not defined

Hi,

I'm an experienced C# guy but new to Javascript.

I have the following function in App Actions -> Scripts and Styles -> Javascript:

window.getEventColor = function (eventTypeId) {
  if (eventTypeId== null) { return; }
  else if (eventTypeId== 3) { return "red" };
  else if (eventTypeId== 12) { return "#008000CC" };
  else { return; }
}

In the 'background color' of a table cell, I have this:

{{ getEventColor(currentRow.EventTypeId) }}

But I get "getEventColor is not defined".

What am I doing wrong?

I also tried creating a Javascript Query and calling it from the 'background color' of a table cell with getEventColor({{ currentRow.EventTypeId }}). Doesn't work either.

function getEventColor(eventTypeId) {
  if (eventTypeId== null) { return; }
  else if (eventTypeId== 3) { return "#F8F8F8CC"; }
  else if (eventTypeId== 12) { return "#008000CC"; }
  else { return; }
}

This is a very basic question: how to define a function in retool. Doesn't eveyone use that in all programming languages?

Anyone?

Hi @Francis!

Looks like there's just a typo when you declared the function on window (which you fixed in subsequent definitions but then weren't declaring on window anymore). Try this?

window.getEventColor = function(eventTypeId) {
if (eventTypeId== null) { return; }
else if (eventTypeId== 3) { return "red"; }
else if (eventTypeId== 12) { return "#008000CC"; }
else { return; }
}

yes that worked--it was a simple typo and I was overthinking it. Thanks!