0

This current script works but searches column 14 in all sheets on the spreadsheet. I only want it to search column 14 on sheet name "Master Crime Spreadsheet".

Thanks in advance for your help

var POST_URL = "DISCORD WEBHOOK URL"

function onEdit(event){
  var sheet_name = event.range.getSheet().getName();
  var rangeNotation = event.range.getA1Notation();
  var oldValue = event.oldValue;
  var value = event.value;
  var items = [];
  var column_id = 14
  if (column_id < event.range.getColumn() || column_id > event.range.getLastColumn() ){
      return;
  }

  if (value == undefined && oldValue == undefined){
    if (rangeNotation.includes(':')){
      reason = "Multiple Cells edited";
    }
    else{
      reason = "Cell value deleted";
    }
  }
  else{
    if (oldValue == undefined){
      oldValue = "Empty cell";
    }

    if (value == undefined){
        value = "Empty cell";
    }
    reason = oldValue + " -> " + value
  }

  items.push({
      "name": "To process go to https://tinyurl.com/xxxxxxxxxxxx",
      "value": "Click doc to go direct to CRIS form: "+ reason,
      "inline": false
  });

  var date = Utilities.formatDate(new Date(), SpreadsheetApp.getActive().getSpreadsheetTimeZone(), "EEE, d MMM yyyy HH:mm:ss Z")



  var options = {
        "method": "post",
        "headers": {
            "Content-Type": "application/json",
        },
        "payload": JSON.stringify({
            "content": "<@&964625157878611998>,<@&964625199129563156>,<@&964625248911753306>",
            "embeds": [{
                "title": "New CRIS Loaded, REACT WITH TICK ONCE PROCESSED",
                "color": 33023,
                "fields": items,
                "footer": {
                    "text": "Timestamp (UTC): "+date
                }
            }]
        })
    };

    UrlFetchApp.fetch(POST_URL, options);
}

1 Answer 1

0

Wrap the desired part with a conditional based on the variable you already created:

if (sheet_name == 'Master Crime Spreadsheet') {

The code you chose

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.