Search code examples
javascriptnetsuitesuitescript

Cannot avoid null values in HTML


I am using a combination of Javascript and HTML to achieve the generation of a PDF inside NetSuite.

I have a loop that I need to ignore the null values but it is not working. The table has 10 column and the idea is to iterate over column2 to ignore null values of the entire table.

The <tr> at the bottom is what I will be printing in the table.

How can I make so that my results exclude the rows for the null values column2 has?

for (let i = 0; i < recordObjs.length; i++) { 
                        if (recordObjs.column2[i] == null) {
                            i++; }
                            

                   htm += `
                    
                        <tr>
                            <td>${recordObjs[i].column0}</td>
                            <td>${recordObjs[i].column2}</td>
                            <td>${numberWithCommas(parseFloat(recordObjs[i].column3), '$')}</td>
                            <td >${recordObjs[i].column4}</td>
                        </tr>`;

                   }

Solution

  • As pointed out already, your initial if statement won’t produce the expected result in the instance where there are two column2 elements in a row with null values. You’ll want to update this by either placing a continue statement within the if block, or possibly placing the logic that follows in the if block and then updating the condition to check if the value is not null.

    If this fails, I would then check to see if your condition is ever true, and if the code in the if block is even hit. (E.g. the value in column2 is an empty string instead of null) Without seeing the full context, it could be that column2 is never actually null.