Zoho Invoices Custom Function - Automate the calculation of some fields

Zoho Invoices Custom Function - Automate the calculation of some fields

So I am using zoho invoices to manage our company's invoices. Recently we needed to add 4 custom fields which are :
1- Number of payments the customer needs to make [ field label is : No of Payments ]
2- Frequency of payments, that is, how frequently the customer needs to make the payment per month [ field label is : Freq of Payments ]
3- Next Payment Amount [ field lablel is : Next Payment amount ]. This one should be auto calculated as follows: 
Next Payment amount = Balance / No of Payments. 
4- Next Billing Date [ field label is Next Billing Date ]. Also auto calculated as follows :
Next Billing Date = invoice date + Frequency of payment. 

The four custom fields above are created and shown in the invoice module fields. 

I created the below code with a workflow but the function executes successfully without any value on next payment amount and next billing date.

<-----------Beginning of the code ------------->

invoiceNumber = invoice.get("Invoice#").toLong();
invoicedate = invoice.get("Date").toDate();
organizationID = organization.get("organization_id").toString();
Balance_N = invoice.get("Balance").toDecimal();
Date_Invoice = invoice.get("Date");
NextPaymentAmount = null;
NextBillingDate = null;
customFieldList = invoice.get("custom_fields").toList();
for each  customField in customFieldList
{
customFieldMap = customField.toMap();
if(customFieldMap.get("label") == "No Of Payments")
{
NoPayments = customFieldMap.get("value");
}
if(customFieldMap.get("label") == "Freq_of_Payments")
{
FreqOfPayments = customFieldMap.get("value");
}
if(customFieldMap.get("label") == "Next_Payment_amount")
{
NextPaymentAmount = customFieldMap.get(Balance_N / NoPayments);
}
if(customFieldMap.get("label") == "Next_Billing_Date")
{
NextBillingDate = customFieldMap.get(invoicedate.addMonth(FreqOfPayments)).toTime();
}
}
info NextPaymentAmount;
info NextBillingDate;
jsonMap = Map();
jsonMap.put("Next_Payment_amount",NextPaymentAmount);
jsonMap.put("Next_Billing_Date",NextBillingDate);
result = zoho.invoice.update("Invoices",organizationID,invoiceNumber,jsonMap);
info result.toMap().get("message");

<-----------End of the code ------------->

    Access your files securely from anywhere







                            Zoho Developer Community




                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                  • Ask the Experts





                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • Functions

                                                                                        Functions

                                                                                      • Meetups

                                                                                        Meetups

                                                                                      • Kbase

                                                                                        Kbase

                                                                                      • Resources

                                                                                        Resources

                                                                                      • Digest

                                                                                        Digest

                                                                                      • CRM Marketplace

                                                                                        CRM Marketplace

                                                                                      • MVP Corner

                                                                                        MVP Corner









                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now


                                                                                            Zoho Show Resources

                                                                                              Zoho Writer

                                                                                              Get Started. Write Away!

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

                                                                                                Zoho CRM コンテンツ



                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方