Skip to content

Instantly share code, notes, and snippets.

@shabdar
Created April 15, 2015 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shabdar/566ef37028e0d74e4568 to your computer and use it in GitHub Desktop.
Save shabdar/566ef37028e0d74e4568 to your computer and use it in GitHub Desktop.
void importInventory()
{
//get contents of the remote CSV file
csv = getUrl("http://yourserver.com/ftp.php");
//create a list and add each row of the csv file into a new list item
line_list = csv.toList("\n");
//empty Products table if today's csv has data.
if (line_list.size() > 0)
{
delete from Products[ Added_Time < zoho.currenttime ];
}
//start importing
for each index i in line_list
{
//skip first row (csv header)
if (i > 0)
{
//get a list item at index
line = line_list.get(i);
//break the line into fields
data_row = line.toList(",");
//extract data values
product_id = data_row.get(0).trim();
product_name = data_row.get(1).trim();
available_stock = (data_row.get(2).trim()).toLong();
unit_price = (data_row.get(3).trim()).toDecimal();
//add a new record into Products
result = insert into Products
[
Added_User = zoho.loginuser
Product_ID = product_id
Product_Name = product_name
Available_Stock = available_stock
Unit_Price = unit_price
];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment