0

Working in the script editor of Google Sheets I have some for/of loops that USED to work, but now for the last few days just give error "Missing ; after for-loop initializer".

In this example I'm iterating through an HTTP response that I've converted tho JSON object. I'm looking for specific readings to add to the table if they are there. The error comes on the line that the loop is designated. The data I'm iterating through it as JSON response. Each item definitely includes the attributes I'm requesting (in this case 'name' and 'name.make'). I've read everything in the docs, in the Javascript docs I can find, both of the SO posts on this topic. Any help is appreciated.

function buildListOfAllEquipmentInOrg() {
  var allMachines = getEquipmentFromMyjdForOrg();
  var allMachinesJson = JSON.parse(allMachines);
  var values = allMachinesJson.values;
  var thisRow = 2;
  var each;
  var sheet = SpreadsheetApp.getActiveSheet();
  
  // Interate through all of values...one per machine.
  for (each of values) {
    sheet.getRange(thisRow, 1).setValue([each.name]);
  }
  sheet.getRange(thisRow, 2).setValue([each.make.name]);
  measurementsLink = extractMeasurementsLink(link);
  }
4
  • Add a sample of the value/object returned by getEquipmentFromMyjdForOrg() Commented Aug 27, 2020 at 23:34
  • It doesn't matter what's in the response because the for loop above is not even allowed to 'save'. I have to change it to a for in loop just to make it save Commented Aug 28, 2020 at 2:18
  • 3
    Did you leave the v8 runtime maybe? You shouldn't get that error there (but you should use for(let each of values) instead). Commented Aug 28, 2020 at 2:36
  • @pguardiario thank you that appears to have solved it!! I don't know how I left it, but I'm back in. Phew. Commented Aug 28, 2020 at 2:48

1 Answer 1

2

As @pguardiario mentioned, the For/Of loops were not working because I was no longer using the Chrome V8 App Script Runtime. I simply had to select the 'run' menu and enable it. There is also a banner that appears when you open the script. I grew so accustomed to seeing the banner indicating I was in v8, that when the banner changed to telling me I was not in V8, I just ignored it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.