var sheet = range.getSheet();
var address = range.getA1Notation();
var conditionalFormatRules = sheet.getConditionalFormatRules();
var conditionalFormatRule = [];
var sheetId = sheet.getSheetId();
for (let index = 0; index < conditionalFormatRules.length; index++) {
let ranges = conditionalFormatRules[index].getRanges();
for (let j = 0; j < ranges.length; j++) {
if (ranges[j].getA1Notation() == address) {
conditionalFormatRule.push({
"deleteConditionalFormatRule": {
"index": index,
"sheetId": sheetId
}
});
}
}
}
if (conditionalFormatRule.length > 0) {
var spreadsheet = SpreadsheetApp.getActive();
var ssId = spreadsheet.getId();
var format_req = {
"requests": conditionalFormatRule
};
Sheets.Spreadsheets.batchUpdate(format_req, ssId);
}
{ [GoogleJsonResponseException: API call to sheets.spreadsheets.batchUpdate failed with error: Invalid requests[8].deleteConditionalFormatRule: No conditional format on sheet: 1876237346 at index: 8] name: 'GoogleJsonResponseException', details: { message: 'Invalid requests[8].deleteConditionalFormatRule: No conditional format on sheet: .... at index: 8', code: 400 } }