【Zoho CRM】カスタム関数:請求書の粗利を計算したい。

【Zoho CRM】カスタム関数:請求書の粗利を計算したい。

Alert
下記はサンプルコードです。カスタム関数のカスタマイズ・デバッグ・テストについてはお客様自身にて行っていただく必要がございます。 ゾーホージャパンサポート窓口では承りかねますので予めご了承ください。

前提条件
  • 請求書タブに「粗利」(種類:数字)という項目が作成されている
※他の項目名を利用する場合は、以下の関数の内容の「粗利」の部分を該当の項目名に置き換えてください。

引数
  • invoiceID =  「請求書」の「請求書のID」


関数の内容
invoice = zoho.crm.getRecordById("Invoices", invoiceID.toLong());
//合計の取得
subTotal=(invoice.get("Sub Total")).toLong();
//原価合計
unitPriceTotal=0;
//商品リストの処理
itemList=invoice.get("product").toJSONList();
for each i in itemList
{
itemMap=i.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",input.invoiceID.toString(),{ "粗利" : grossProfit });
return "登録しました!";

※ワークフローのカスタム関数で設定する場合は最後の行(return "登録しました!";)を削除してください。


Info
参考情報