'Compare multiple strings in one conditional if in Google Sheets
I would like to do the following with Google Apps Script:
- Compare more than two strings corresponding to different versions of the same car model
- Match the correct model
- Use a Google Doc template with the model's info
Here you can find part of my code:
const rows = sheet.getDataRange().getValues();
var googleDocTemplate = DriveApp.getFileById('doc ID')
rows.forEach(function(row,index) {
if (index === 0) return;
if (row[0]) return;
if (row[3]==='Toyota') return;
if (row[3]==='Ford') return;
if (row[3]==='Dodge') return;
if (row[3]==='Changan') return;
if (row[15]==='' && row[22]==='') return;
//Grand i10 M/T GL, GLS or A/T GLS
if ((row[4].equals('Grand i10 M/T GL') || row[4].equals('Grand i10 M/T GLS') || row[4].equals('Grand i10 A/T GLS')) && row[9]===0 && row[6]==='Electric Blue'){
googleDocTemplate = DriveApp.getFileById('doc ID');
}
else if ((row[4].includes('Grand i10 M/T GL') || row[4].includes('Grand i10 M/T GLS') || row[4].includes('Grand i10 A/T GLS')) && row[9]===0 && row[6]==='Black'){
googleDocTemplate = DriveApp.getFileById('doc ID');
}
else {
SpreadsheetApp.getUi().alert("Hyundai model is wrong")
return
}
Basically the code search through rows in the Google Sheets like this
and then compares the string contained in the cell with the reference string (e.g 'Grand i10 M/T GL'), but in this particular case, the conditional jumps straight to the else showing the alert "Hyundai model is wrong".
Any help would be appreciated. Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

