Last active
December 29, 2020 21:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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