'How to check if column status is null with Google App Script?
I try for use Google App Script as backend, I have some columns and some columns are not filled so all of them are still output, I want my script to run and output data if all the columns I provided are filled
+----+-------+------+
| a | b | c |
+----+-------+------+
| 1 | Item1 | pub | publish/output
+----+-------+------+
| 2 | Item2 | | not publish/output
+----+-------+------+
| 3 | | pub | not publish/output
+----+-------+------+
function doGet(e) {
var page = e.parameter.page || 1;
var limit = e.parameter.limit || 10;
var search = e.parameter.search || "";
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/10S8Igzt1tpqUBgJHVKpny-2s6G3Y3-vFsLMvlZVqpkc/edit#gid=810612111");
var sheet = ss.getSheetByName("list_film");
return getUsers(sheet, page, limit, search);
}
function getUsers(sheet, page, limit, search){
var lowCase = search.toString().toLowerCase();
var rows = sheet.getDataRange().getValues().filter(([,,c]) => c.toString().toLowerCase().includes(lowCase));
var dataArray = rows.splice(limit * (page - 1), limit).reduce((ar, [a, b, c, d]) => ar.concat({id: a, year: b, title: c, img: d}), []);
var jo = {};
jo.user = dataArray;
var result = JSON.stringify(jo);
return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.JSON);
}
Solution 1:[1]
In your script, how about the following modification?
From:
var dataArray = rows.splice(limit * (page - 1), limit).reduce((ar, [a, b, c, d]) => ar.concat({id: a, year: b, title: c, img: d}), []);
To:
var dataArray = rows.splice(limit * (page - 1), limit).reduce((ar, [a, b, c, d]) => {
if (b != "" && c != "") ar.push({ id: a, year: b, title: c, img: d });
return ar;
}, []);
- In this case, when the cells of columns "B" and "C" have the values, the row is retrieved. But from
{ id: a, year: b, title: c, img: d }, if you want to check the columns "C" and "D" instead of "B" and "C", please modifyif (b != "" && c != "")toif (c != "" && d != "").
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tanaike |
