invoice = zoho.crm.getRecordById("Invoices",input.invoiceID.toLong());
//合計の取得
subTotal=(invoice.get("Sub_Total")).toLong();
//原価合計
unitPriceTotal=0;
//商品リストの処理
items=invoice.get("Product_Details");
for each item in items
{
itemMap=item.toMap();
//原価
unitPrice=(itemMap.get("unit_price")).toLong();
quantity=(itemMap.get("quantity")).toLong();
unitPriceTotal=(unitPriceTotal + unitPrice * quantity);
}
//値引き
discount = invoice.get("Discount").toLong();
//調整
adjustment=invoice.get("Adjustment").toLong();
//粗利の算出
grossProfit=(subTotal - unitPriceTotal-discount + adjustment);
//粗利の更新
resp = zoho.crm.updateRecord("Invoices",invoiceID.toLong(),{ "粗利のAPI名" : grossProfit });
return "登録しました!";