Google Apps Script Conditional If/Else If Statemen

2019-01-29 13:07发布

问题:

I've got this script below but it keeps returning the incorrect information. For instance, even though the "urgency" may equal "medium", it returns the "critical" result.

var initialcontact;
var row = sheet.getActiveRange().getRowIndex();
var urgency = sheet.getRange(row, getColIndexByName("Urgency")).getValue();
if (urgency = "Critical") {initialcontact = "1 hour";}
else if (urgency = "High") {initialcontact = "4 hours";}
else if (urgency = "Medium") {initialcontact = "1 day";}
else if (urgency = "Low") {initialcontact = "3 days";}

回答1:

You should use == for comparing , not =

if (urgency == "Critical")

and so on..