Advertisement
Guest User

Untitled

a guest
Jan 24th, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function myFunction() {
  2.   var ss = SpreadsheetApp.getActiveSpreadsheet();
  3.   var sourceSheet = ss.getSheetByName("raw data");
  4.   var destSheet = ss.getSheetByName("myFunction results");
  5.   var sourceData = sourceSheet.getRange(2, 1, sourceSheet.getLastRow() - 1, sourceSheet.getLastColumn()).getValues();
  6.  
  7.   //Add name to each column, add here if you have more columns
  8.   sourceData.forEach(function (x) {
  9.     x[8] = x[6] + ":\n" + x[8] // col 8 Status
  10.     x[9] = x[6] + ":\n" + x[9] // col 9 Priority
  11.     x[10] = x[6] + ":\n" + x[10] // col 10 Finalized
  12.     x[12] = x[6] + ":\n" + x[12] // col 12 Org Pillars LE
  13.     x[13] = x[6] + ":\n" + x[13] // col 12 Org Pillars REI
  14.     x[14] = x[6] + ":\n" + x[14] // col 12 Org Pillars LOP
  15.     x[15] = x[6] + ":\n" + x[15] // col 12 Org Pillars GF
  16.   });
  17.  
  18.   var array = sourceData,
  19.     hash = {},
  20.     i, j,
  21.     result,
  22.     item,
  23.     key;
  24.  
  25.   for (i = 0; i < array.length; i++) {
  26.     item = array[i];
  27.     key = item[0].toString();
  28.     if (!hash[key]) {
  29.       hash[key] = item.slice();
  30.       continue;
  31.     }
  32.     for (j = 1; j < item.length; j++) hash[key][j] = hash[key][j] + "\n" + item[j];
  33.   }
  34.  
  35.   result = Object.values(hash);
  36.   destSheet.getRange(2, 1, result.length, result[0].length).setValues(result);
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement