Duplicating Child Line Items Conditionally

Hello,
I have been trying 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 field value.

Quote:
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
{
}

what do you mean exactly?

you only want to duplicate related foundset that are named (by relation name) in a field/dataprovider?

var relatedFsArray = new Array(global.myrelationanme1,global.myrelationanme1);

Hi Jan,
Thanks for the reply sorry if I was not clear enough. I will try to explain

What I am trying to do is duplicate a purchase order and some of the related line item records based on the status of the line item. eg “stock item is on back order” so include.

so why can’t you just check the value of a related column before you duplicate it or not?