title: Setup flag in Javascript
body: <p>Below is a script I am using for a Google Docs Spreadsheet. </p>
  
  <p>These links show what I am doing:</p>
  
  <p><a href="http://i.stack.imgur.com/uGik7.png" rel="nofollow">http://i.stack.imgur.com/uGik7.png</a></p>
  
  <p><a href="http://i.stack.imgur.com/AbKnQ.png" rel="nofollow">http://i.stack.imgur.com/AbKnQ.png</a></p>
  
  <p>How can I set up a "flag" so that when I run this script a second time, it doesn't add the perviously added stock items?</p>
  
  <pre><code>function myFunction() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet1 = ss.getSheetByName("Purchase Orders");
    var sheet2 = ss.getSheetByName("Inventory");
    var data = sheet1.getDataRange();
    var i_data = sheet2.getDataRange();
    var lastRow = data.getLastRow();
    var iLastRow = i_data.getLastRow();
  
    for (i=1;i&lt;=lastRow;i++) {
      if (data.getCell(i, 5).getValue() == "stock"){
        for (n=1;n&lt;=iLastRow;n++){
          if (data.getCell(i,3).getValue() == i_data.getCell(n,3).getValue()) {
          i_data.getCell(n, 1).setValue(i_data.getCell(n,1).getValue() + data.getCell(i,2).getValue());
         }
        }
      }
  
    }
  }​
  </code></pre>
  
  <p>I guess I'm trying to do this: Once the item has been added to inventory, the script adds an x to column i of that line. Then when the script is run again, it skips over the lines with an x in column i </p>