Hi Jeff
I think Bill is right in that you can't use Javascript to delete records from libraries. I think this is a Memento issue as there is definitely a delete method in Javascript.
Anyway I've written some code to save closed cases from one library to another (see end of this post). If nothing else, it will be a starting point for the time when the developer implements a delete function in Memento. I should re-emphasise that I've only used Javascript for a few weeks, and then only as a hobbyist. So I wouldn't use this code if money and/or someone's health depends on it.
I've assumed your main library is called 'All Cases' and has three variables;
1) Unique Id - this is an Integer variable which is set to auto-increment;
2) Operation - a text variable which records the operation.
3) Active - The single choice list which you suggested. It can take the values Open or Closed.
I've set the entry name to unique.
The second library is called 'Closed File' and has the Unique ID and operation variables.
The JS code is attached to an action trigger. When it runs it goes through the following steps:
1) Initialise some key variables which reference the libraries
2) Check if the 'All Cases' file contains any cases. If not then the script will terminate;
3) Loop through each case in the 'All Cases file'
4) If the single-choice variable is set to Closed, then the script runs an inner loop on all cases in the 'Closed File'. If it finds any cases where the Unique Id is a match then it sets a flag which stops the case from being saved.
5) If the case is closed and not already on the closed file then it will be saved to the closed file.
A few points to bear in mind:
1) I've done some basic tests on it and it seems to work as described. However I knocked this out fairly quickly so it may well not be bug-free.
2) It is also not the most efficient code e.g if step 4 finds a match on the first case in the closed file it will check all of the other cases for a match. This will soon get cumbersome for large files, so I will try and fix this in a few days time;
3) It contains some messages which helped me understand the control flow. They're not essential to the code of course;
4) It works as an action script. I'm guessing it could be placed into a trigger script so you could just apply it when a case was updated.
Thanks
Chris
****************** CODE STARTS HERE ***********************************
// Saving closed records to another file
// Variable to reference the operation library, array of entries and number of entries
var oplib=lib();
var opent=lib().entries();
var oplen=opent.length;
// exit if operation library is empty
if (oplen<=0)
{
message ("No records in main file - closing the script");
exit();
}
// Variables to reference closed case library, and array of entries
var cllib=libByName("Closed File");
var clent=libByName("Closed File").entries();
var cllen=clent.length;
// Loop through current library
// And identify closed cases
for (var ent=0; ent<oplen; ent++)
{
var clsdflag= opent[ent].field("Active");
if (clsdflag==="Closed")
{
// if closed, need to check
// they aren't already on the closed case file
message("Looping through a closed case");
// Initialize flag which tests if entry already on closed case file
var newflag=1;
// Set-up the loop through closed case file
// At the moment it doesn't loop if the closed file is empty
for (var chk=0; chk<cllen; chk++)
{
var messtext2=("Case ") +(ent) + (" on operation file and case ") + ( chk) + (" on closed file");
message (messtext2);
// Check for a matching Unique Id obn closed case file
if (opent[ent].field("Unique Id")===clent[chk].field("Unique Id"))
{
// Set flag to show entry already.on
// closed file
message (("Case ") + (ent) + (" matches with case ") + (chk) + (" on closed file"));
newflag=0;
}
}
// Save in closed file if not already there
// message (("Newflag is ") + (newflag));
if (newflag===1)
{
message ("Saving to closed file");
var newentry= new Object();
newentry["Unique Id"]=opent[ent].field("Unique Id");
newentry["Operation"]=opent[ent].field("Operation");
cllib.create(newentry);
}
}
}