I am working on a project that involves Zoho Flow. We created a custom function that should update the item stock and status based on the sales order. However, when I try to run it I get error 57 (Unauthorized Access). I've tried multiple things and it still doesn't work. The connection seems fine when I tested it but it still work run.
See code below:
string Update_stock_or_change_inactive_item(string salesOrderId, string organization)
{
output = "";
salesOrder = zoho.inventory.getRecordsByID("SalesOrders",organization,salesOrderId);
output = salesOrder + " ";
productDetails = ifnull(salesOrder.get("line_items"),"");
lineitems = productDetails.toJSONList();
for each item in lineitems
{
itemMap = item.toMap();
productId = ifnull(itemMap.get("product_id"),"");
productName = ifnull(itemMap.get("name"),"");
quantity = ifnull(itemMap.get("quantity"),"0");
product = zoho.inventory.getRecordsByID("Items",organization,productId);
productMap = product.toMap();
//get product stock
availableStock = ifnull(productMap.get("actual_available_stock"),"0");
availableStockForSale = ifnull(productMap.get("actual_available_for_sale_stock"),"0");
status = ifnull(productMap.get("status"),"");
output = output + status;
//check and update stock
if(availableStock < quantity || availableStockForSale < quantity)
{
//update item to ensure that it is in stock
new_values = Map();
new_values.put("actual_available_stock",quantity);
new_values.put("actual_available_for_sale_stock",quantity);
new_values.put("status","active");
response = zoho.inventory.updateRecord("Items",organization,productId,new_values);
output = output + productName + " - stock updated to " + quantity + ", ";
}
else if(status != "active")
{
new_values.put("status","active");
output = output + productName + " - status updated to active, ";
}
else
{
output = output + productName + " stock not updated, ";
}
}
return output;
}