Hi everybody.
Need some help with a piece of javascript. I know nothing of javascript, but I have set up a script build upon two of the trigger examples. The first part is the one I think is giving the error. The second part is working good.
The trigger event type are "creating an entry" and "updating an entry" and both in the "after saving the entry" phase.
The goal of the triger script is to create a new entry in another library if the conditions are fulfilled.
I used the "New entry in one library triggers new entry in another" example for the second part of the script and for the first part the "Ensuring unique non-Name field value" example of the Trigger Examples of the wiki.
My group layout is:
INCIDENCIAS library:(entry name is unique, entry name "NÚMERO:"
-NÚMERO:(integer autoincrement)(name)
-CLIENTE:(link to entry to CLIENTES library
-FECHA:(date)(status)
-ETIQUETA:(calculation)(status)
-LUGAR:(location)
-PRIORIDAD:(single-choice list)(status)
-ESTADO:(single-choice list)
-FACTURAR(boolean)
-DESCRIPCIÓN:(text)(description)
-FOTOS:(image)
-HORAS:(real number)
CLIENTES library:(entry name is unique, entry name "Número de cliente:", "Nombre:")
-Número de cliente:(integer autoincrement)(name)
-Nombre:(text)(name)
-NIF:(text)(description)
-Dirección:(text)(description)
-Teléfono:(phone number)(description)
-Email:(text)
FACTURAS libray:(entry name is unique, entry name "Número:")
-Número:(integer autoincrement)(name)
-Número de albarán:(integer)(status)
-Fecha:(text)(status)
-Cliente:(text)(description)
-NIF:(text)
-Dirección:(text)
-Concepto:(text)(description)
-Precio:(integer)(status)
I'm trying to set up a kind of "work order with invoicing" and, of course, lern how to use this wanderful app.
The trigger is set up in the "INCIDENCIAS" library with all permissions.
The script is:
var albaran = entry().field("NÚMERO:");
var numeroDeEntradas = libByName("FACTURAS").entries();
var albaranNoExiste = true;
for (var ent = 0; ent < numeroDeEntradas.length; ent++) {
if (numeroDeEntradas[ent].field("Número de albarán:") == albaran)
albaranNoExiste = false;
}
var e = entry();
if (albaranNoExiste && e.field("FACTURAR") && e.field("ESTADO:") == "RESUELTO") {
var factura = libByName("FACTURAS");
var nuevafactura = new Object();
nuevafactura["Cliente:"] = e.field("CLIENTE:").field("Nombre:");
nuevafactura["Número de albarán:"] = e.field("NÚMERO:");
nuevafactura["Fecha:"] = moment(e.field("FECHA:")).format("DD/MM/YYYY");
nuevafactura["NIF:"] = e.field("CLIENTE:").field("NIF:");
nuevafactura["Dirección:"] = e.field("CLIENTE:").field("Dirección:");
nuevafactura["Precio:"] = e.field("HORAS:")*10;
factura.create(nuevafactura);
}
The darken part was working ok, but I added the first part just to add the "albaranNoExiste" condition in the dark part that is traying to avoid the creation of a new entry in "FACTURAS" library if the current "NÚMERO:" value does already exist as "Número de albarán:" in "FACTURAS" library.
After adding that and testing the script with the "play" button it says "succssecfully executed" but when updating an entry in "INCIDENCIAS" library that matches all the conditions to create a new entry in "FACTURAS" library I get this error:
TypeError: Cannot find function field in object [com.luckydroid.droidbase.triggers.objects.JSEentry@28e69e8]. (Fecturar edición.js#16)
I hope the problem is just a simple thing. As I told before I have no idea of javascript, but I think Memento is going to get lot of us into that world.
Any help will be apreciated.
Thanks.