-1
  1. Now the script logs rows

  2. Instead of logging rows I want to set values to those rows

  3. I want to change the "Logger.log" to "setValue"

    function add(){ var mainsname ='MIIST'; var ss = SpreadsheetApp.getActiveSpreadsheet(); var mainss = ss.getSheetByName(mainsname); var adcnumber = ss.getRangeByName('AD').getColumn(); var sacnumber = ss.getRangeByName('SA').getColumn(); var dicnumber = ss.getRangeByName('DI').getColumn(); var range = mainss.getDataRange(); var data = range.getValues().slice(1); data.forEach((row)=>{

    if(row[sacnumber-1] !== "" && row[dicnumber-1] =="" ){Logger.log(row[dicnumber-1]);}

    } ) }

Kal El
  • 53
  • 6
  • It is unclear what the desired end result is. Do you just want to log the data, or do you want to store it somewhere in the spreadsheet? – doubleunary Jun 11 '22 at 11:09
  • You example does not meet the requirements for [mcve] because we do not know have the nameranges are defined. Please provide a real [mcve] – Cooper Jun 11 '22 at 15:21
  • I revised the question to make it clearer – Kal El Jun 11 '22 at 17:17
  • This question has been reposted in [How to make "setValue" work inside a foreach in Google Sheets App Script](https://stackoverflow.com/q/72589451/13045193). – doubleunary Jun 12 '22 at 06:53

1 Answers1

0

To log the values in the row, use console.log(row);.

To append data to the end of the sheet, use Array.filter() and Sheet.appendRow(), like this:

  const result = data.filter(row => row[sacnumber - 1] !== '' && !row[dicnumber - 1]);
  result.forEach(row => mainss.appendRow(row));
doubleunary
  • 13,842
  • 3
  • 18
  • 51
  • Thank you but I don't want to log the data, instead of logging it I would like to set a value (setValue for each row) – Kal El Jun 11 '22 at 11:11
  • To append data to the end of the sheet, use the second recipe I gave above. Please edit your question to explain, in detail, what the desired end result is. – doubleunary Jun 11 '22 at 14:26
  • I revised the question to make it clearer – Kal El Jun 11 '22 at 17:16
  • Understood. To append data to the end of the sheet, replace your `data.forEach()` block with the two lines of code I gave you. If you do not want to append the data, but to write it to a fixed location, please explain, in detail, what the desired end result is. – doubleunary Jun 11 '22 at 19:55