Problem with Mass creation of invoices
I have a script to generate an 'x' amount of invoices. Recently I'm facing the problem where in example, if I tell the script to create 120 invoices; the script stops working when it creates 70 invoices, and the rest don't get created. The script used to work fine and could create even up to 160 invoices. Below is the following error, and an example of the script that creates the invoices.
Error details:
Error in executing On Edit - On Success script.
Value is empty and 'get' function cannot be applied Line:(63)
Info Value:
EnviarMensaje: {"code":400
"data":{"error_message":"The request URL is invalid. Please check the URL pattern."
"error_key":"security.url.invalid"
"error_code":9022}
"status":"FAILED"}
- PlazoAcordado = 120;
fecha = "17/09/2020";
FechaPago1 = fecha.toDate();
ContactoZBooks = 888587000033680404;
IDOportunidad = 2234337000069294002;
amount = 333.33;
IDProductoBooks = 888587000012337389;
Terrenos = "VILLA PRUEBA M1-L1";
PrimerMensualidad = true;
paymentlist = "p".leftpad(PlazoAcordado).replaceall(" ","p,").tolist();
paymentno = 1;
SaldoT = 0;
if(PrimerMensualidad == true)
{
paymentlist = "p".leftpad(PlazoAcordado - 1).replaceall(" ","p,").tolist();
NoPago = paymentno + 1;
}
else if(PrimerMensualidad == false)
{
paymentlist = "p".leftpad(PlazoAcordado).replaceall(" ","p,").tolist();
NoPago = paymentno;
}
for each rec in paymentlist
{
FechaPago2 = FechaPago1.addMonth(paymentno);
invoiceMap = Map();
item1 = Map();
itemList = List();
invoiceMap.put("customer_id",ContactoZBooks);
invoiceMap.put("zcrm_potential_id",IDOportunidad);
SaldoT2 = SaldoT.ToLong();
SaldoT = SaldoT.ToLong() - amount.ToLong();
//Finaliza busqueda del producto en Z-Books
item1.put("item_id",IDProductoBooks);
item1.put("rate",amount);
item1.put("quantity",1);
item1.put("description","Pago por Concepto de Mensualidad " + NoPago + " " + "de" + " " + PlazoAcordado + " Lote " + Terrenos);
MapaCPBooks = Map();
ListaCP = List();
MapaCPBooks.put("label","Concepto");
MapaCPBooks.put("value","Mensualidad");
ListaCP.add(MapaCPBooks);
invoiceMap.put("custom_fields",ListaCP);
itemList.add(item1);
invoiceMap.put("line_items",itemList);
invoiceMap.put("date",FechaPago2);
invoiceMap.put("terms","");
invoiceMap.put("reference_number",NoPago + " " + "de" + " " + PlazoAcordado + " Lote " + Terrenos);
invoiceMap.put("due_date",FechaPago2);
info "Iter: " +NoPago+ "----" + invoiceMap;
CreaFactura = zoho.books.createRecord("Invoices","651425182",invoiceMap);
if(CreaFactura == null || CreaFactura.get("code") != 0)
{
CreaFactura = zoho.books.createRecord("Invoices","651425182",invoiceMap);
if(CreaFactura == null || CreaFactura.get("code") != 0)
{
CreaFactura = zoho.books.createRecord("Invoices","651425182",invoiceMap);
}
}
if(CreaFactura.get("code") == 0)
{
DatosFactura = CreaFactura.get("invoice");
IDFactura = DatosFactura.get("invoice_id");
organizationID = "651425182";
authtoken = "515f2ad19583f91152ceecb72637c2b8";
json = Map();
json.put("authtoken",authtoken);
res = postUrl("https://books.zoho.com/api/v3/invoices/" + IDFactura + "/status/sent?organization_id=" + organizationID,json);
}
info "Iter: " +NoPago+ "----" + CreaFactura;
paymentno = paymentno + 1;
NoPago = NoPago + 1;
}