Duplicating Line Items Condionally

Hello,
I have been tring to work this one out, and would really appreciate some help please. I have successfully used the following method for duplicating parent and child records, I would like to do the same but selectively choosing the child relation based on a feild value.

var answer = plugins.dialogs.showDialog(‘Alert’,‘Do you want to build Backorder?’,‘Yes’,‘No’)
if(answer == “Yes”)

{
var fs = foundset;
var relatedFsArray = new Array(‘purchases_to_purchase_line_items’);

// Duplicate master record.
var dup = fs.getRecord(fs.duplicateRecord(false,false));

// save is needed if DB_IDENT sequence is used!!
currentcontroller.saveData();

for(var k=0;k<relatedFsArray.length;k++)
{
var related = fs[relatedFsArray[k]];
for(var i=1;i<=related.getSize();i++)
{
var relatedOriginal = related.getRecord(i);
var relatedDub = dup[relatedFsArray[k]].getRecord(dup[relatedFsArray[k]].newRecord(false,false));
databaseManager.copyMatchingColumns( relatedOriginal, relatedDub);
}
}

//goto new duplicated record
//foundset.selectRecord(dup.purchasesid)
//forms.logistics_holder.elements.tabs_70.tabIndex = 3

backorder_status = 1

currentcontroller.saveData();

}
else
{
}

I’m not sure I get the problem, I don’t really see one. In stead of hard coded you want the value to be based on a field is that right? if so just replace the hard coded value with the value of the field?