Reputation: 21
I'm using an if statement on the condition if a cell has a value of 'TRUE', if it does I want another cell to have the value given in the statement
I'm using this to work out which boxes have been checked. So if one box is checked it shows 'TRUE', then I want the other cell to show the action that the box has checked for. e.g if the purchasing box is ticked, I want the other cell to show 'Purchased'.
var submit_type_corrective = submit_sheet.getRange('B6').getValue();
var submit_type_Opportunity = submit_sheet.getRange('B7').getValue();
var submit_type_Preventative =submit_sheet.getRange('E7').getValue();
var type_submitted = log_sheet.getRange(lastRow_log+1,3);
if (submit_type_corrective == 'TRUE'){
type_submitted.setValue('Corrective');
}
else if (submit_type_Opportunity == 'TRUE'){type_submitted.setValue('Opportunity')}
else {type_submitted.setValue('Preventative')
}
I want the cell to show Corrective, but it displays with nothing even though the box is checked
Upvotes: 0
Views: 40
Reputation: 1533
Range.getValue()
returns a value as its corresponding type (e.g., number, boolean, date, or string).
The default underlying type of of checkbox cells in Google Sheets is boolean, not string.
Try changing:
if (submit_type_corrective == 'TRUE') {
to
if (submit_type_corrective == true) {
or simply
if (submit_type_corrective) {
And similarly, you'll have to update:
if (submit_type_Opportunity == 'TRUE') {
to
if (submit_type_Opportunity == true) {
or
if (submit_type_Opportunity) {
Tip: You can inspect the type of values in Google Apps Script by doing
Logger.log(typeof submit_type_corrective);
Upvotes: 1