0

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";}
2
  • Presumably, the script you're using started out as the Help Desk tutorial. If so, it would be helpful to others for you to include that in the question - it gives background that may help resolve problems, and gives credit to the original authors. Commented Dec 5, 2013 at 17:19
  • I didn't begin with the Help Desk tutorial, but when I found it I did take parts from it...didn't think to include that. Sorry for any confusion. Commented Dec 5, 2013 at 18:27

1 Answer 1

2

You should use == for comparing , not =

if (urgency == "Critical")

and so on..

Sign up to request clarification or add additional context in comments.

5 Comments

Ok, I made that change but it is now coming back as "undefined"
Which variable is returning undefined ? Please also post the sample spreadsheet data
The initialcontact variable is returning as undefined in the spreadsheet...almost as if urgency = undefined but it doesn't. The sample is that I have a column with the listed "Urgency", for example "High", and then in the column "Initial Contact" I want it to return a variable accordingly, so if urgency was high, it would return "4 hours".
Did you change all 4 comparisons to ==?
In addition to what Fred says, add a Logger.log() to print out the value of urgency . This is a very simple script and there is nothing else that can go wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.