simple inventory management system using Google Apps Script

Here is a source code for a simple inventory management system using Google Apps Script:

function checkInventory() {

  var sheet = SpreadsheetApp.getActiveSheet();

  var data = sheet.getDataRange().getValues();

  

  var message = "Inventory:\n";

  

  for (var i = 1; i < data.length; i++) {

    var item = data[i][0];

    var quantity = data[i][1];

    message += item + ": " + quantity + "\n";

  }

  

  Browser.msgBox(message);

}


function updateInventory(item, amount) {

  var sheet = SpreadsheetApp.getActiveSheet();

  var data = sheet.getDataRange().getValues();

  

  for (var i = 1; i < data.length; i++) {

    if (data[i][0] == item) {

      var newQuantity = parseInt(data[i][1]) + amount;

      sheet.getRange(i+1, 2).setValue(newQuantity);

      break;

    }

  }

}


function submitForm(e) {

  var item = e.response.getItemResponses()[0].getResponse();

  var amount = parseInt(e.response.getItemResponses()[1].getResponse());

  updateInventory(item, amount);

}


function onOpen() {

  var ui = SpreadsheetApp.getUi();

  ui.createMenu('Inventory')

      .addItem('Check inventory', 'checkInventory')

      .addToUi();

}


 

To use this code:

  1. Create a new Google Sheet.
  2. Copy and paste the code into the Script Editor (Tools > Script editor).
  3. Save the script and reload the Google Sheet to activate the onOpen() function.
  4. Go to the "Inventory" menu and select "Check inventory" to display the current inventory.
  5. To add or subtract items, create a form with a multiple-choice question for the item name and a number question for the amount. Then, link the form to the submitForm() function using a trigger (see steps 6 and 7 in my previous answer).

Comments

Popular posts from this blog

Git commands

How to Debug Android TV App using IP