title: Why isn't it sending the values from the correct row via Email?
body: <p>The code below sends one email containing the name of the item, its version and its current status, once the user makes some changes. Since the product can go through 06 statuses, there is one column for each status, where the script will mark "Sim" if an email has already been sent containing the update on that item.</p>
  
  <p>The code marks the right rows and columns, but the message contains data for another product, instead.</p>
  
  <p>I got the <code>MailApp</code> in the loop, tried adding a counter to stop it from sending as it loops through the rows, but no success so far.</p>
  
  <pre><code>var EMAIL_SENT = "Sim";
  function sendEmails() {
    var file = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("ArquivoItens");
    var startRow = 2;  // First row of data to process
    var numRows = sheet.getLastRow();   // Number of rows to process
    // Fetch the range of cells A7:s3
    var dataRange = sheet.getRange(startRow, 1, numRows, 48)
    var data = dataRange.getValues();
    var productList = [];
    var counter = 0;
    for (var i = 0; i &lt; data.length; ++i) {
      var rowData = data[i];
      if (rowData[18] === "Estudo" || rowData[18] === "Desenvolvimento" || rowData[18] === "Aprovação" || rowData[18] === "Ativo" || rowData[18] === "Cancelado" || rowData[14] === "Descontinuado") {
        var status = rowData[18];
        var emailEstudo = rowData[42];    
        var emailDesenvolv = rowData[43];
        var emailAprov = rowData[44];
        var emailAtivo = rowData[45];
        var emailCancelado = rowData[46];
        var emailDescont = rowData[47];
        if (emailDesenvolv != EMAIL_SENT &amp;&amp; status === "Desenvolvimento") {  // Prevents sending duplicates 
          sheet.getRange(startRow + i, 44).setValue(EMAIL_SENT);
          SpreadsheetApp.flush();    
        } else if(emailEstudo != EMAIL_SENT &amp;&amp; status === "Estudo") {  // Prevents sending duplicates 
          sheet.getRange(startRow + i, 43).setValue(EMAIL_SENT);
          SpreadsheetApp.flush();
        }else if(emailAprov != EMAIL_SENT &amp;&amp; status === "Aprovação") {  // Prevents sending duplicates 
          sheet.getRange(startRow + i, 45).setValue(EMAIL_SENT);
          SpreadsheetApp.flush();
        }else if(emailAtivo != EMAIL_SENT &amp;&amp; status === "Ativo") {  // Prevents sending duplicates 
          sheet.getRange(startRow + i, 46).setValue(EMAIL_SENT);
          SpreadsheetApp.flush();
        }else if(emailCancelado != EMAIL_SENT &amp;&amp; status === "Cancelado") {  // Prevents sending duplicates 
          sheet.getRange(startRow + i, 47).setValue(EMAIL_SENT);
          SpreadsheetApp.flush();
        }else if(emailDescont != EMAIL_SENT &amp;&amp; status === "Descontinuado") {  // Prevents sending duplicates 
          sheet.getRange(startRow + i, 48).setValue(EMAIL_SENT);
          SpreadsheetApp.flush();
        }
        var produto = rowData[1];
        var versao = rowData[2];
        var lastUpdated = rowData[19];
        var lastUpdatedAsDate = Utilities.formatDate(lastUpdated, SpreadsheetApp.getActive().getSpreadsheetTimeZone(), "dd/MM/yyyy HH:mm") + "hs";
        var usuario = rowData[20];
        var emailTo = file.getOwner().getEmail();
        var subject = "O produto " + produto + ", versão " + versao + " " +", mudou de status.";
        var message =  "&lt;HTML&gt;&lt;BODY&gt;"
        + "&lt;P&gt;Olá!"
        //+ "&lt;br&gt;&lt;br /&gt;"
        + "&lt;P&gt;O status do produto " + produto + ", versão " + versao + ", foi atualizado para " + "&lt;b&gt;" +status +"&lt;/b&gt;" + "."
        //+ "&lt;brr /&gt;&lt;br /&gt;"
        + "&lt;br&gt;Data da última atualização:  &lt;/b&gt;" + lastUpdatedAsDate + "&lt;br /&gt;"
        + "&lt;br&gt;Usuário: &lt;/b&gt;" + usuario + "&lt;br /&gt;"
        + "&lt;br /&gt;&lt;br /&gt;"    
        //+ "&lt;br&gt;Clique para explorar detalhes, ou para atualizar o status: &lt;/b&gt;" + "https://docs.google.com/spreadsheets/d/15pL_AMKVtH4dGk1U7VWMeg590MxtNe7VY4gRqm_GhrM/edit?usp=sharing" + "&lt;br /&gt;" 
        + "&lt;br /&gt;&lt;br /&gt;"  
        + "&lt;/HTML&gt;&lt;/BODY&gt;";  
      }  
  
    }
    MailApp.sendEmail({
            name: "P&amp;D - PB",
            to: emailTo,
            //cc: emailCC,
            subject: subject, 
            htmlBody: message
          });
  }
  </code></pre>
  
  <p>Here's a <a href="https://docs.google.com/spreadsheets/d/1N6znnKQIIDvTK1A4PLgQbLxAdTXTQ53HncaeeoQ77zE/edit?usp=sharing" rel="nofollow noreferrer">link to the data.</a></p>
  
  <p>Here's a print that explains the challenge:
  <a href="https://i.stack.imgur.com/yGfY6.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yGfY6.jpg" alt="enter image description here"></a></p>
  
  <p>I appreciate your help in finding where the problem sits besides me in this chair!</p>