Help

How do I filter out null values

Topic Labels: Scripting extentions
2265 4
cancel
Showing results for 
Search instead for 
Did you mean: 

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()
    }
4 Replies 4
Erin_OHern
6 - Interface Innovator
6 - Interface Innovator

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:
Image 2021-01-19 at 8.44.13 am
Image 2021-01-19 at 8.41.43 am

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.

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.

YourFriend
6 - Interface Innovator
6 - Interface Innovator

I am having this issue with my script. It is iterating through a column that has linked record data in it (An Object) which is a person’s name.

The column name it is iterating through is ‘Primary Introducer (from Investor)’

Although not every cell in the column has an object in it. Some are empty. When that is the case I get an error.

Error Being:
TypeError: Cannot read properties of null (reading ‘0’)
at main on line 45

Any help would be appreciated

Script:

let lookupTable = base.getTable("Orders");
let lookupRangeRecords = await lookupTable.selectRecordsAsync();

let invoiceTable = base.getTable("Generate Invoice");
let invoiceTableRangeRecords = await invoiceTable.selectRecordsAsync();
//I do not think I need an invoice table lookuprangerecords variable


    for (let rangeRecord of lookupRangeRecords.records) {

        let lookupValue = "John Smith"

        
        if (rangeRecord.getCellValue("Primary Introducer (from Investor)")[0].name === lookupValue) {

            let returnValueInvestorName = rangeRecord.getCellValue("Investor")[0].name;
            let returnValueInvestment = rangeRecord.getCellValue("Investment");
            let returnValueShares = rangeRecord.getCellValue("Shares");
            let returnValuePrimaryIntroducerCashFee = rangeRecord.getCellValue("Primary Introducer Cash Fee");
            let returnValuePrimaryIntroducerEquityFee = rangeRecord.getCellValue("Primary Introducer Equity Fee");

            await invoiceTable.createRecordAsync({
                "Investor": returnValueInvestorName,
                "Investment": returnValueInvestment,
                "Shares": returnValueShares,
                "Cash Fee": returnValuePrimaryIntroducerCashFee,
                "Equity Fee": returnValuePrimaryIntroducerEquityFee
            });
        }
    }
     for (let rangeRecord of lookupRangeRecords.records) {
        let lookupValue = "John Smith"
        if (rangeRecord.getCellValue("Secondary Introducer (from Investor)")[0].name  === lookupValue) {

            let returnValueInvestorName = rangeRecord.getCellValue("Investor")[0].name;
            let returnValueInvestment = rangeRecord.getCellValue("Investment");
            let returnValueShares = rangeRecord.getCellValue("Shares");
            let returnValueSecondaryIntroducerCashFee = rangeRecord.getCellValue("Secondary  Introducer Cash Fee");
            let returnValueSecondaryIntroducerEquityFee = rangeRecord.getCellValue("Secondary Introducer Equity Fee");

            await invoiceTable.createRecordAsync({
                "Investor": returnValueInvestorName,
                "Investment": returnValueInvestment,
                "Shares": returnValueShares,
                "Cash Fee": returnValueSecondaryIntroducerCashFee,
                "Equity Fee": returnValueSecondaryIntroducerEquityFee
            });
        }
     }
    for (let rangeRecord of lookupRangeRecords.records) {
        let lookupValue = "John Smith"
        //Make it for tertiary introducer
        if (rangeRecord.getCellValue("Tertiary Introducer (from Investor)")[0].name ===  lookupValue) {
            console.log("Tertiary Hit")
            console.log(rangeRecord)
            //console.log(rangeRecord.getCellValue("Investor")[0].name)
            //console.log(rangeRecord.getCellValue("Primary Introducer Cash Fee"))
            let returnValueInvestorName = rangeRecord.getCellValue("Investor")[0].name;
            let returnValueInvestment = rangeRecord.getCellValue("Investment");
            let returnValueShares = rangeRecord.getCellValue("Shares");
            let returnValueTertiaryIntroducerCashFee = rangeRecord.getCellValue("Tertiary Introducer Cash Fee");
            let returnValueTertiaryIntroducerEquityFee = rangeRecord.getCellValue("Tertiary Introducer Equity Fee");
            //console.log(returnValueInvestorName);
            // Returning too many values. Looping too many times.
            await invoiceTable.createRecordAsync({
                "Investor": returnValueInvestorName,
                "Investment": returnValueInvestment,
                "Shares": returnValueShares,
                "Cash Fee": returnValueTertiaryIntroducerCashFee,
                "Equity Fee": returnValueTertiaryIntroducerEquityFee
            });
        } 
    }

Wrapped everything in If Statements

if( x !== null)