Skip to content

Instantly share code, notes, and snippets.

@Adrian-Samuel
Last active December 29, 2020 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adrian-Samuel/9ce4eb80c2309e9fd6c6f6e323a0b44e to your computer and use it in GitHub Desktop.
Save Adrian-Samuel/9ce4eb80c2309e9fd6c6f6e323a0b44e to your computer and use it in GitHub Desktop.
javascript (app script) to provide live validation on length of sms message within a given cell
function onEdit({source, range}) {
const {
columnStart,
rowStart
} = range
const nextCellR1C1Notation = `R${rowStart}C${columnStart + 1}`
if (columnStart == 3) {
const adjacentCell = source.getActiveSheet().getRange(nextCellR1C1Notation)
const cellCharacterLength = range.getValue().toString().length
if (cellCharacterLength > 0) {
if (cellCharacterLength <= 50) {
adjacentCell.setValue("A bit short");
adjacentCell.setBackground("lightblue")
}
if (cellCharacterLength > 50 && cellCharacterLength <= 100) {
adjacentCell.setValue("A decent length");
adjacentCell.setBackground("orange")
}
if (cellCharacterLength > 100 && cellCharacterLength <= 150) {
adjacentCell.setValue("A good length");
adjacentCell.setBackground("lightgreen")
}
if (cellCharacterLength > 150) {
adjacentCell.setValue("Too Long")
adjacentCell.setBackground("#ffcccb")
}
} else {
adjacentCell.setValue("");
adjacentCell.setBackground("white")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment