Advertisement
RemcoE33

u/mayaswelltrythis - replace "Suggestion"

Jul 16th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Makes many calls to the sheet api..
  2. function getTranslationSuggestions() {
  3.   //Change sheetname
  4.   const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data');
  5.   //Change starting row
  6.   const startRow = 2;
  7.   const data = sheet.getRange(startRow, 1, sheet.getLastRow(), 5).getValues();
  8.  
  9.   for (i = 0; i < data.length; i++) {
  10.     const row = data[i];
  11.     if (row[2] === 'Suggestion' && row[3] !== 'OK') {
  12.       sheet.getRange(i + startRow, 3).setValue(row[4])
  13.     }
  14.   }
  15. }
  16.  
  17. //Build the hole dataset and makes one write call to the sheet.
  18. function getTranslationSuggestionsReplaceHoleDataSet() {
  19.   //Change sheetname
  20.   const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data');
  21.   //Change starting row
  22.   const startRow = 2;
  23.   const data = sheet.getRange(startRow, 1, sheet.getLastRow(), 5).getValues();
  24.  
  25.   const converted = data.map(row => {
  26.     if (row[2] === 'Suggestion' && row[3] !== 'OK'){
  27.       row[2] = row[4]
  28.       return row
  29.     } else {
  30.       return row
  31.     }
  32.   })
  33.  
  34.   sheet.getRange(startRow,1,converted.length, 5).setValues(converted)
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement