Record dulication

I have the following code to duplicate a record and line items:

// Save All reocrds to memory
var lineitems = productsalesorders_to_productsalesorderlineitems;

// Capture the number of records
var count = productsalesorders_to_productsalesorderlineitems.getSize()

//Duplicates and selects a new master record
foundset.duplicateRecord(foundset.getSelectedIndex() ,true,true)

//loop on previously saved detail records
for (var i = 1; i <= count ; i++)
{
//Duplicates the line Items
lineitems.duplicateRecord(i,false,true);

//Assigns the new master primary
lineitems.product_sales_order_number = product_sales_order_number;
}
controller.saveData();

Everything works great.

I have added ‘fieldA’ (Check Box) to the productsalesorderlineitems table. I want to loop through the line items, and duplicate only the checked line items, to the new order. And remove them from the original order.

Option 1
I was not sure how / where to impliment this. I would think that if I could save only those check at this point;

// Save All reocrds to memory
var lineitems = productsalesorders_to_productsalesorderlineitems;

then I could just loop through the line items that are checked on the original order and delete them.

Option 2
Loop through the records through the records during the duplication point and duplicate the checked line items then delete them from the original order at this point;

//loop on previously saved detail records
for (var i = 1; i <= count ; i++)
{
//Duplicates the line Items
lineitems.duplicateRecord(i,false,true);

//Assigns the new master primary
lineitems.product_sales_order_number = product_sales_order_number;
}

ex:
productsalesorders_to_productsalesorderlineitems.fieldA = ‘true’

I was not sure about the easiest way to accomplish this.

Did you check out this thread?
It contains a good global script from jcompagner how to duplicate records.