In case it gets lost in the previous thread, as I could see it had a lot of views .....
If you want a simple function to update the item purchase price to the latest bill received then you can use the following to accomplish this....
Custom function for bills
billItems = bill.get("line_items");
for each line in billItems
{
rate = line.get("rate");
id = line.get("item_id");
res = zoho.books.getRecordsByID("items",organization.get("organization_id"),id);
item = res.get("item");
rateNow = item.get("purchase_rate");
if(rateNow != rate)
{
myMarkup = 1.5; // this is your markup if you want to amend the sales price by a margin of the buying price - replace the 1.5 with your choice
newSellPrice = rate
* myMarkup;
newRate = Map();
newRate.put("purchase_rate",rate);
//newRate.put("rate",newSellPrice); // un-comment this if you want to amend the sales price
result = zoho.books.updateRecord("items",organization.get("organization_id"),id,newRate);
}
}
If you're struggling to set this custom function up then let us know - we'll walk you through it !