Javascript Installation Icon

Below is the script that I use for the Google Docs spreadsheet.

These links show what I am doing:

http://i.stack.imgur.com/uGik7.png

http://i.stack.imgur.com/AbKnQ.png

How to configure the β€œflag” so that when you run this script again, it does not add previously added stock items?

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<=lastRow;i++) { if (data.getCell(i, 5).getValue() == "stock"){ for (n=1;n<=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()); } } } } }​ 

I am assuming I'm trying to do this: as soon as an item has been added to inventory, the script adds x to the column i of this row. Then, when the script runs again, it skips the rows with x in column i

+4
source share
3 answers

In JavaScript, functions are objects. Objects have properties. So, decorate your function:

 function myFunction() { if (!myFunction.alreadyDoneRunIt) { alert('bapt uia'); myFunction.alreadyDoneRunIt = true; } } for (var i = 0; i < 10; i++) { myFunction(); // alerts once } 
+2
source

Assign a cell to store the flag value and check the script for this specific cell for the flag value.

+3
source

First add the values ​​to the array. Every time you add an element, check the array to see if it is already in it. Then loop your array to the message in the user interface.

Here's a message to help check if the array already contains a value. fooobar.com/questions/232 / ...

+1
source

Source: https://habr.com/ru/post/1332048/


All Articles