Custom Function for updating expiry date of Invoice failed due to Invalid Date specified in Custom Field

Custom Function for updating expiry date of Invoice failed due to Invalid Date specified in Custom Field

Hi,

We have an issue which we did not encountered prior to 26 Apr.
Basically we have a custom function, that is used to update the expiry date of the invoice. As our payments terms are based on end-of-months of xx days.
Inclusive as well, in the invoice, we have a custom field DATE, that defines when we actually send the invoice to the client through a separate portal. The format of the custom field DATE (cf_posted_data) is dd/MM/yyyy (that matches our Zoho Books Org date setting).

As we are only updating the expiry date of the invoice, the custom function works successfully when custom field DATE  (cf_posted_data)  is blank.
But if there is a DATE value  (cf_posted_data)  e.g. 23/05/2022, the custom function fails with the error:
 "code": 6, "message": "Invalid date 23/05/2022 specified."
Would anyone be able to provide some insights?

  1. invoiceID = invoice.get("invoice_id");
  2. invoicedate = invoice.get("date").toDate();
  3. organizationID = organization.get("organization_id");
  4. invoicepaymenttermslabel = invoice.get("payment_terms_label");
  5. invoicepaymenttermsdays = invoice.get("payment_terms");

  6. x_day = 0;
  7. if(invoicepaymenttermsdays == "121")
  8. {
  9. x_day = 120;
  10. }
  11. else if(invoicepaymenttermsdays == "91")
  12. {
  13. x_day = 90;
  14. }
  15. //OBTAIN THE END OF THE MONTH POST x days
  16. newinvoiceduedate = invoice.get("date").addDay(x_day).eomonth(0);
  17. DuenumberOfDays = daysBetween(invoicedate,newinvoiceduedate);
  18. invoice.put("due_in_days",DuenumberOfDays);
  19. //FORMAT THE NEW DUE DATE
  20. newupdatedinvoiceduedate = toString(newinvoiceduedate,"yyyy'-'MM'-'dd");
  21. newinvoiceduedateformatted = toString(newinvoiceduedate,"dd'/'MM'/'yyyy");
  22. invoice.put("due_date",newupdatedinvoiceduedate);
  23. invoice.put("due_date_formatted",newinvoiceduedateformatted);
  24. invoice.put("billing_address","");
  25. invoice.put("shipping_address","");
  26. //UPDATE INVOICE
  27. updatedinvoice = zoho.books.updateRecord("Invoices","2XXXXXXXXXXX",invoiceID,invoice);
  28. info updatedinvoice;

Thanks