How do I filter out null values

I have a bunch of dates I need to convert to strings and put into an object.
sometimes however my date field is empty and it comes up as null

As far as I understand checking if something is truthy I can just check it with if(value) and it only runs if value is truthy - not null, undefined…

However even despite el.getCellValue(wipDate) comes up as null, my code still runs the blog inside the if statement.

Does anyone know what I’m doing wrong?

    let month = '';
    let year = null;
    let dateObj = {'year':year, 'month':months[month]};
        
    console.log(el.getCellValue(wipDate))   

    if(el.getCellValue(wipDate)){
        //console.log('inside')
        month = months[new Date(el.getCellValue(wipDate)).getMonth()]
        year = new Date(el.getCellValue(wipDate)).getFullYear()
    }

Hi Kim,

Hmm… I’m not able to reproduce what you’re describing, using this simple script:

let table = base.getTable('Table 1')
let query = await table.selectRecordsAsync();
let records = query.records;

for(let rec of records) {
    let date = rec.getCellValue('Date');
    output.inspect(date);
    if(date) {
        console.log('here');
    }
}

Here’s my table set up, and the results of my script:


We don’t have your full script so it’s hard to say exactly what might be going on, but hopefully that snippet I used might help identify any issues! If you’re able to share your entire script, showing how and where el is being set, that will also help.

1 Like

Thank you @Erin_OHern
I have since reworked my script so I don’t have it any longer myself either.
I was just pretty sure it did not work - however it is definately possible I’ve starred myself blind on it and there was something leading up to it not working as anticipated.