How to table check on empty value in table if its not empty based on user input Bot should responce

Hi Team

The code aims to verify if a specific table column, denoted as ‘Remit_Code,’ possesses any non-empty values. It scrutinizes the data table received as a response, specifically examining the ‘Remit_Code’ column for non-empty cells. Should the column contain data, the code captures the first non-empty value and stores it in a variable named nonEmptyRemitCodeValue for subsequent use. Additionally, it logs this non-empty value and ensures its storage in the Bot User Session under the key ‘nonEmptyRemitCodeValue,’ recognizing the intention to utilize it in a later if condition

function isRemitCodeColumnEmpty() {
try {
// Access the data table and the ‘Remit_Code’ column
var remitCodeTable = context.CallDataTable &&
context.CallDataTable.response &&
context.CallDataTable.response.body &&
context.CallDataTable.response.body.queryResult
? context.CallDataTable.response.body.queryResult[0].Remit_Code
: null;

    // Check if the data table and 'Remit_Code' column are available and not empty
    if (remitCodeTable && remitCodeTable.rows && remitCodeTable.rows.length > 0) {
        // Set the columnIndex to 7 (assuming 'Remit_Code' is the eighth column, zero-based index)
        var columnIndex = 7;
        var isEmpty = true;
        var nonEmptyRemitCodeValue = null;

        // Iterate through each row in the 'Remit_Code' column
        for (var i = 0; i < remitCodeTable.rows.length; i++) {
            // Access the cell in the 'Remit_Code' column for the current row
            var cell = remitCodeTable.rows[i].cells && remitCodeTable.rows[i].cells[columnIndex];

            // Check if the cell is not null and not empty or only contains whitespace
            if (cell && cell.trim() !== '') {
                // Store the non-empty value of 'Remit_Code'
                nonEmptyRemitCodeValue = cell.trim();
                isEmpty = false; // Set isEmpty to false as soon as a non-empty cell is found
                break; // Exit the loop if a non-empty cell is found
            }
        }

        if (isEmpty) {
            console.log("Remit_Code column is empty or contains only whitespace.");
            BotUserSession.put("isEmpty", "isEmpty");
        } else {
            console.log("Non-empty value of Remit_Code:", nonEmptyRemitCodeValue);
            BotUserSession.put("nonEmptyRemitCodeValue", nonEmptyRemitCodeValue);
        }

        // Print the values of variables
        console.log("Value of Remit_Code Table:", remitCodeTable);
        console.log("Is Remit_Code column empty?", isEmpty);
        console.log("Non-empty value of Remit_Code:", nonEmptyRemitCodeValue);

        return !isEmpty; // Return true if not empty, false otherwise
    } else {
        // Handle the case where the data table or 'Remit_Code' column is not available
        console.error("Data table or 'Remit_Code' column not found.");
        return false;
    }
} catch (error) {
    // Handle other potential errors
    console.error("An error occurred:", error.message);
    return false;
}

}

isRemitCodeColumnEmpty()