Creating custom column using .find() and returning 0 for nulls instead of null

Hello all,

I am fairly new to javascript and ReTool. I am building an application with a custom column with the code below. Just to preface, virCount is data from a 'Query JSON with SQL' query, after pulling data from a Google Sheet API.

{{>x['Employee Name'] === currentRow['Name'])['Days Completed'] }} 

The code works well for rows that have a match, however, there are some values that return null. I would like to replace those values with 0 instead. Any advice?

Thank you so much.

Hello @cdiep

Please could you give us more context, if possible a screenshot of some dummy data from the state of['Employee Name']

Where are the null values being returned?

Is it as a result of the full expression or the function x=>x['Employee Name'] === currentRow['Name']\

In the table, there is a full list of employee names. In the, there are only names of employees who completed a certain form. I would like to return 0 for the employees that are not in the virCount query, aka the ones that did not fill anything out.

Hey @cdiep!

You might want to use optional chaining here, the find function should return undefined if it can find a record with the current row's name which will throw an error if you try and access the Days Completed property on it. So this should ensure your transformer doesn't error:>x['Employee Name'] === currentRow['Name'])?.['Days Completed']

Instead it will just return undefined so you can then use the nullish coalescing operator ?? which returns the left argument if it's not null or undefined and the right argument otherwise, put that all together and you get:

{{>x['Employee Name'] === currentRow['Name'])?.['Days Completed'] ?? 0 }}

Can you let me know if that works?