Updating an Invoice Line Item's Discount Account via API Call / Deluge Custom Function

Updating an Invoice Line Item's Discount Account via API Call / Deluge Custom Function

I need help updating an invoice line item's discount account via API. Below is a screenshot of the line item field I am referring to.

Now the field to the left of the highlighted field (discount account) is the sales income account. I am able to modify the sales income account via API completely fine.

I have a custom field called "Sales Account" with four options: Direct, Retail, Event, House Account, and Subscription. This field is in the invoices module.

This workflow has no criteria and immediately triggers the custom function "update_income_accounts," which fetches the invoice's "Sales Account" field value and runs through a series of if/else statements to determine the correct account ID for the sub-accounts nested under the main chart of accounts sales income account.


We're trying to automate updating the sales account association for all invoice line items by running this custom function.

So far, it works perfectly, except for the line item discount account. I can't get the invoice to reflect any changes to the discount account.


Below is the Zoho Books Custom Function I am using that works to update the Sales Income account but fails to reflect any change to the Discount account

  1. sales_account_value = "";
  2. account_id = "";
  3. discount_id = "";
  4. for each  custom_field in invoice.get("custom_fields")
  5. {
  6. if(custom_field.get("field_id") == "4366441000017151041")
  7. {
  8. sales_account_value = custom_field.get("value_formatted");
  9. }
  10. }
  11. if(sales_account_value == "Direct")
  12. {
  13. account_id = "4366441000017139067";
  14. discount_id = "4366441000036176472";
  15. }
  16. else if(sales_account_value == "Retail")
  17. {
  18. account_id = "4366441000017139058";
  19. discount_id = "4366441000036176510";
  20. }
  21. else if(sales_account_value == "Event")
  22. {
  23. account_id = "4366441000017134275";
  24. discount_id = "4366441000036176506";
  25. }
  26. else if(sales_account_value == "House Account")
  27. {
  28. account_id = "4366441000036176498";
  29. discount_id = "4366441000036176502";
  30. }
  31. else if(sales_account_value == "Subscription")
  32. {
  33. account_id = "4366441000041000009";
  34. discount_id = "4366441000041000015";
  35. }
  36. invoice_ID = invoice.get("invoice_id");
  37. line_items = Map();
  38. url = "https://www.zohoapis.com/books/v3/invoices/" + invoice_ID + "?organization_id=HIDDEN_FOR_HELP";
  39. invoice_details = invokeurl
  40. [
  41. url :url
  42. type :GET
  43. connection:"HIDDEN_FOR_HELP"
  44. ];
  45. line_items = invoice_details.get("invoice").get("line_items");
  46. item_to_update = List();
  47. for each  item in line_items
  48. {
  49. line_item_map = Map();
  50. line_item_map.put("line_item_id",item.get("line_item_id"));
  51. line_item_map.put("account_id",account_id);
  52. // set discount account via the discounts array
  53. discount_details = item.get("discounts");
  54. info discount_details;
  55. discounts_list = List();
  56. one_discount = Map();
  57. one_discount.put("discount_order",discount_details.get(0).get("discount_order"));
  58. one_discount.put("discount_amount",discount_details.get(0).get("discount_amount"));
  59. one_discount.put("discount_percent",discount_details.get(0).get("discount_percent"));
  60. one_discount.put("discount_account",discount_id);
  61. discounts_list.add(one_discount);
  62. line_item_map.put("discount_account_id",discount_id);
  63. line_item_map.put("discounts",discounts_list);
  64. item_to_update.add(line_item_map);
  65. info discounts_list;
  66. }
  67. info item_to_update;
  68. update_payload = Map();
  69. update_payload.put("line_items",item_to_update);
  70. update_invoice = invokeurl
  71. [
  72. url :url
  73. type :PUT
  74. parameters:update_payload.toString()
  75. connection:"HIDDEN_FOR_HELP"
  76. ];


      Zoho Campaigns Resources


        • Desk Community Learning Series


        • Digest


        • Functions


        • Meetups


        • Kbase


        • Resources


        • Glossary


        • Desk Marketplace


        • MVP Corner


        • Word of the Day


        • Ask the Experts


          Zoho CRM Plus Resources

            Zoho Books Resources


              Zoho Subscriptions Resources

                Zoho Projects Resources


                  Zoho Sprints Resources


                    Zoho Orchestly Resources


                      Zoho Creator Resources


                        Zoho WorkDrive Resources



                          Zoho CRM Resources

                          • CRM Community Learning Series

                            CRM Community Learning Series


                          • Tips

                            Tips

                          • Functions

                            Functions

                          • Meetups

                            Meetups

                          • Kbase

                            Kbase

                          • Resources

                            Resources

                          • Digest

                            Digest

                          • CRM Marketplace

                            CRM Marketplace

                          • MVP Corner

                            MVP Corner




                            Zoho Writer Writer

                            Get Started. Write Away!

                            Writer is a powerful online word processor, designed for collaborative work.

                              Zoho CRM コンテンツ



                                ご検討中の方