I am trying to sort a range of data in a Google Sheets spreadsheet based on the values in a single column AND using a custom sort order. I am able to sort the data, but I can't figure out how to set the priority for sorting (other than alphabetically or reverse alphabetically). I would like to sort based on the order indicated below, but obviously what I have now just does it alphabetically. Help much appreciated!
function onEdit() {
var sheet = SpreadsheetApp.getActiveSheet();
var editedCell = sheet.getActiveCell();
//sort based on priority
var columnToSortBy = 4;
var tableRange = "A2:Q1000";
var SortOrder = [
{name: "Urgent", value:1},
{name: "High Priority", value:2},
{name: "Moderate Priority", value:3},
{name: "No deadline", value:4},
{name: "Complete", value:5}
];
if(editedCell.getColumn() == columnToSortBy){
var range = sheet.getRange(tableRange);
range.sort( { column : columnToSortBy } ); //this needs to be sorted based on priority level, not
}
}