--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/CACDFz-stTMP7q-JDA3aS7dVqiGW0eRJs5Getu82xv-nNdGrZFg%40mail.gmail.com.
var e = entry();
//X2 eng Table
var LBNx2 = libByName("X2 eng");
var entriesx2 = LBNx2.entries();
var l2 = entriesx2.length;
//X1 eng Table
var name1 = e.field("Name 1");
//
for ( var i=0;((i<l2)&&(name1 != name2));i++)
{
var name2 = entriesx2[i].field("Name 2");
var id2 = entriesx2[i].id;
var record2ID = LBNx2.findById(id2);
var nomixe = entriesx2[i].field("nbr of modifications in X2 eng");
var newDate = new Date();
if ( name1 === name2 )
{
record2ID.set("Result X1 in X2 eng",e.field("Result in X1 eng"));
record2ID.set("nbr of modifications in X2 eng",nomixe +1);
record2ID.set("Last Update",newDate)
}
};
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/f8e756bb-d012-4724-aedb-9f640f5069ean%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/37e52e75-0696-445f-949e-188e0b094d1cn%40googlegroups.com.
var e = entry();
// in Widgets
var A = libByName("Widgets");
var ent = A.entries();
var l = ent.length;
// in Widget Acquisitions
var bcB = e.field("Barcode");
for (var b in bcB )
var bcB2 = bcB[b].field("Barcode");
var wa = (e.field("Widgets / Box") * e.field("Boxes Acquired"))
;
for (var i=0;((i<l)&&(bcB2!=bcA));i++)
var bcA = ent[i].field("Barcode");
var countA = ent[i].field("Count");
{
if ( bcA === bcB2)
e.set("test",wa)
};
var e = entry();
// in Widgets
var A = libByName("Widgets");
var ent = A.entries();
var l = ent.length;
// in Widget Acquisitions
var bcB = e.field("Barcode");
for (var b in bcB )
var bcB2 = bcB[b].field("Barcode");
var wa = (e.field("Widgets / Box") * e.field("Boxes Acquired"))
;
for (var i=0;((i<l)&&(bcB2!=bcA));i++)
{
var bcA = ent[i].field("Barcode");
var idA = ent[i].id;
var recordA= A.findById(idA)
if ( bcA === bcB2)
recordA.set("Count",wa)
};
--
for (var i=0;((i<l)&&(bcB2!=bcA));i++)
{
var bcA = ent[i].field("Barcode");
var idA = ent[i].id;
var recordA = A.findById(idA)
var countA = recordA.field("Count")
if ( bcA === bcB2)
recordA.set("Count",countA+wa)
message (countA)
};
--
This is basically working. Thanks! I'd like to understand it better, because I might make some modifications. I've made some notes on the code of what I think it is doing. Please let me know what I'm misunderstanding, and help me with the loops.
var e = entry(); // Calling this entry
// in Widgets
var A = libByName("Widgets"); // The Widgets Library
var ent = A.entries(); // A list of the entries in the Widgets Library
var l = ent.length; // The number of entries in the Widgets Library?
// in Widget Acquisitions
var bcB = e.field("Barcode"); // The Barcode field in the current entry
for (var b in bcB ) // Loop of some kind?
var bcB2 = bcB[b].field("Barcode"); // ???
var wa = (e.field("Widgets / Box") * e.field("Boxes Acquired")) // Multiplying the Widgets per Box by the Boxes Acquired.
;
for (var i=0;((i<l)&&(bcB2!=bcA));i++) // Loop checking the barcode field in the current entry against entries in the Widgets Library
{
var bcA = ent[i].field("Barcode");
var idA = ent[i].id; // The entry id of the entry with a Barcode field matching the current entry
var recordA= A.findById(idA) // Finding the entry with the above id
if ( bcA === bcB2) // If the Barcode field of the entry in the Widgets library EXACTLY matches the Barcode field in the current entry then...
recordA.set("Count",wa) // In the Count field of the entry in the Widgets Library enter the (wa) Widgets Acquired value.
};
Thanks!
--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/CACDFz-vtzfUoxyV1PtOXXAfO-XG0ci%3DRhvg-zC5D_TpGfrozMg%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/CACDFz-vtzfUoxyV1PtOXXAfO-XG0ci%3DRhvg-zC5D_TpGfrozMg%40mail.gmail.com.
J'ai un peux de temps alors voilà...
J'expliquerai ici que ce que je pense que vous n'avez pas compris ou compris partiellement....
var l = ent.length;
/* l = à la taille du tableau des entrées de la bibliothèque Widgets */
var wa = (e.field("Widgets / Box") * e.field("Boxes Acquired")) /* on fait le calcul que vous faites dans votre champ "Widgets Acquired" mais on ne peut pas le récupérer car votre champ est un champ javascript, donc ont refait le calcul */
var idA = ent[i].id;
//ont peux comprendre: dans les entrées de la base Widgets[index de l'enregistrement, dans la boucle].identifiant mementodatabase
La chose importante à comprendre est que la condition dans la boucle "for" (bcB2 != bcA)doit être l'inverse de la condition du "if" ( bcA === bcB2)
Même si la variable bcA est déclarer après, ce n'est pas important, car nous la déclarons avec "var", si on l'avais déclarer avec "let" on aurais du la déclaré avant la boucle...
I have a little time so here ...
I will explain here that what I think you did not understand or partially understood .... var l = ent.length; / * l = the size of the Widgets library entry array * /
var wa = (e.field ("Widgets / Box") * e.field ("Boxes Acquired")) / * we do the calculation you do in your "Widgets Acquired" field but we cannot retrieve it because your field is a javascript field, so have redone the calculation * /
var idA = ent [i] .id;
// can understand: in the Widgets database entries [record index, in the loop]. mementodatabase identifier
The important thing to understand is that the condition in the "for" loop (bcB2! = BcA) must be the inverse of the condition in the "if" (bcA === bcB2)
Even if the variable bcA is declared after, it is not important, because we declare it with "var", if we had declared it with "let" we should have declared it before the loop ...
var bcB = e.field("Barcode");
for (var b in bcB )
var bcB2 = bcB[b].field("Barcode");
var e = entry();
//Base X2 fr
var LBNx2 = libByName("X2 fr");
var entréesx2 = LBNx2.entries();
var l2 = entréesx2.length;
//Base X1 fr
var nom1 = e.field("Nom 1");
//
for ( var i=0;((i<l2)&&(nom1 != nom2));i++)
{
var nom2 = entréesx2[i].field("Nom 2");
var id2 = entréesx2[i].id;
var enregistrement_x2= LBNx2.findById(id2);
var ndm = entréesx2[i].field("nbr de modifications");
var nouvDate = new Date();
if ( nom1 === nom2 )
{
enregistrement_x2.set("Résultat 2",e.field("Résultat 1"));
enregistrement_x2.set("nbr de modifications",ndm+1);
enregistrement_x2.set("Dernière Mise à Jour",nouvDate);
}
};
--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/CAJkz3e3NGvzFqsabGRmCc9T%2Bf0vbHwMfHcLx7vf2Lm0eAFoSyA%40mail.gmail.com.
if ( NEWcount < 0 ) // Test if the new 'Widget Remaining' count will be negative...
{
message ("Number Expended exceeds Widgets Remaining. Canceling changes."); //Notify user
e.set("Number Expended", pv); // Reset Expended to previous value
e.set("Previous Value", ''); // Reset Previous to blank
exit(); // Stop running the trigger script. Entry will save with previous value and not change Inventory or Remaining fields in linked libraries.
}
This worked fine in the 'Update before save' script. It modified the correct linked fields. I didn't get messages as if the script was trying to modify every Acquisitions and Inventory entry.
When I tried to move it over to the 'Creating before save' script the script was not working. Before I stared mucking around the creating script was working. Not sure what I did. As I was writing this message, and continuing to troubleshoot so I could provide as much info here, I found I was missing the block brackets after an if test.
--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/CACDFz-tgBrnYsCZHvsJ8wqs9Ef2ryANSZTxGZzDeXJU0wOk7Pg%40mail.gmail.com.
Use the method defaultEntry(), rather than entry(), to get the DefaultEntry object (the unstored template, if you will, for the eventual Entry object)."
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/405b7d12-c717-48d5-8b72-9771169c0d75n%40googlegroups.com.
var e = entryDefault();
// in Widgets
var A = libByName("Widgets");
var ent = A.entries();
var l = ent.length;
// in Widget Acquisitions
var bcB = e.field("Barcode");
for (var b in bcB )
var bcB2 = bcB[b].field("Barcode");
var wa = e.field("Widgets Acquired");
e.set("Widgets Remaining",wa);
var wr = e.field("Widgets Remaining");
for (var i=0;((i<l)&&(bcB2!==bcA));i++)
{
var bcA = ent[i].field("Barcode");
var idA = ent[i].id;
var recordA = A.findById(idA);
var countA = recordA.field("Count");
var NEWcount = countA + wr;
if ( bcA === bcB2)
recordA.set("Count",NEWcount),
message ("Updated inventory count to " + NEWcount)
};
--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/e9edfb88-dd17-4161-861a-cc9d450e2580n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/f51dd707-7a74-460a-bc2f-5ccd9c3d4669n%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/CAJkz3e0_jqVYw9fdfrNXdFm%3DW9fNTqJC%2BZqcSapG%3DKANGxb65w%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/f51dd707-7a74-460a-bc2f-5ccd9c3d4669n%40googlegroups.com.
var e = entry();
// in Widgets
var A = libByName("Widgets");
var entA = A.entries();
var lA = entA.length;
// in Widget Acquisitions
var B = libByName("Widget Acquisitions");
var entB = B.entries();
var lB = entB.length;
// in Widget Expenditures
var bcC = e.field("Barcode");
for (var b in bcC)
var bcC2 = bcC[b].field("Barcode");
var acC = e.field("AcID");
for (var a in acC)
var acC2 = acC[a].field("AcID");
var we = e.field("Number Expended");
for (var r=0;((r<lB)&&(acC2!==acB));r++)
{
var acB = entB[r].field("AcID");
var idB = entB[r].id;
var recordB = B.findById(idB);
var countB = recordB.field("Widgets Remaining");
if ( acB === acC2 )
{
var NEWcount = countB - we;
if ( NEWcount < 0 ) // Test if the new 'Widget Remaining' count will be negative...
{
message ("Number Expended exceeds Widgets Remaining. Canceling changes."); //Notify user
e.set("Number Expended","");//☆ // Reset Expended to previous value
//☆e.set("Previous Value", ''); // Reset Previous to blank
exit(); // Stop running the trigger script. Entry will save with previous value and not change Inventory or Remaining fields in linked libraries.*/
}//☆
else//☆
{//☆
recordB.set(e2.field("Widgets Remaining"),NEWcount),
message ("Decreasing " + acB + " remaining count to " + NEWcount)
for (var i=0;((i<lA)&&(bcC2!==bcA));i++)
{
var bcA = entA[i].field("Barcode");
var idA = entA[i].id;
var recordA = A.findById(idA);
var countA = recordA.field("Count");
var NEWcount = countA - we;
if ( bcA === bcC2)
{
recordA.set("Count",NEWcount),
message ("Decreasing " + bcA + " inventory count to " + NEWcount)
}
}
}//☆
};//☆
};
for (var i=0;((i<l)&&(bcB2!==bcA));i++)
var countA = recordA.field("Count");
var NEWcount = countA + wr;
if ( bcA === bcB2)
recordA.set("Count",NEWcount),
message ("Updated inventory count to " + NEWcount)
};
var e = entry();
// in Widgets
var A = libByName("Widgets");
var entA = A.entries();
var lA = entA.length;
// in Widget Acquisitions
var B = libByName("Widget Acquisitions");
var entB = B.entries();
var lB = entB.length;
// in Widget Expenditures
var bcC = e.field("Barcode");
for (var b in bcC)
var bcC2 = bcC[b].field("Barcode");
var acC = e.field("AcID");
for (var a in acC)
var acC2 = acC[a].field("AcID");
var we = e.field("Number Expended");
for (var r=0;((r<lB)&&(acC2!==acB));r++)
{
var acB = entB[r].field("AcID");
var idB = entB[r].id;
var recordB = B.findById(idB);
var countB = recordB.field("Widgets Remaining");
if ( acB === acC2 )
{
var NEWcount = countB - we;
if ( NEWcount < 0 ) // Test if the new 'Widget Remaining' count will be negative...
{
message ("Number Expended exceeds Widgets Remaining."); // notify user
cancel (); // Cancel the save operation
exit(); // Stop running the trigger script.
};
recordB.set("Widgets Remaining",NEWcount),
message ("Decreasing " + acB + " remaining count to " + NEWcount)
}};
for (var i=0;((i<lA)&&(bcC2!==bcA));i++)
{
var bcA = entA[i].field("Barcode");
var idA = entA[i].id;
var recordA = A.findById(idA);
var countA = recordA.field("Count");
var NEWcount = countA - we;
if ( bcA === bcC2)
{
recordA.set("Count",NEWcount), message ("Decreasing " + bcA + " inventory count to " + NEWcount)
}}
If I run it as above, it will notify the user and keep the entry creation window open, but if the check mark is tapped again it will save the entry and subtract from the Inventory Count (but not 'Widgets Remaining'). If I remove the cancel() function and include your line that clears 'Number Expended', it will save the entry with an empty 'Expended' field. I think I prefer keeping the entry open, so it could be fixed.