Hey guys. Nice to meet all of you at servoy camp (thanks again Harjo & Karel).
I’m having a problem duplicating a Parent with related child records in 6.0.9. I’m using this code that seems to be pretty standard (there’s a few posts about it on the forum, including one from Bevil that he never figured out)
onAction:
/**
* @properties={typeid:24,uuid:"a7ada411-ea3e-444e-8f80-ed91744e989e"}
*/
function duplicate_estimate_with_children()
{
globals.g_duplicate_record_with_children(foundset, new Array('Parent_To_Child_Relation'));
}
global:
/**
* @properties={typeid:24,uuid:"84be5a6d-182d-4751-9bfe-34f229aba44e"}
* @param {JSFoundset} fs parent (sales)
* @param {Array} relatedFsArray relation from parent to children
*/
function g_duplicate_record_with_children(fs, relatedFsArray)
{
fs = arguments[0];
relatedFsArray = arguments[1];
// Duplicate master record.
var dup = fs.getRecord(fs.duplicateRecord(false));
// save is needed if DB_IDENT sequence is used!!
currentcontroller.saveData();
for(var k=0;k<relatedFsArray.length;k++)
{
/**@type {JSFoundset} related*/
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));
databaseManager.copyMatchingFields( relatedOriginal, relatedDub);
}
}
currentcontroller.saveData();
}
It seems whatever I do the Array created by the onAction method has only one value (relatedFSArray.length returns [1]). Which means all the loops don’t work. The relation works correctly for other things on the same form, which leads me to think i’m doing something wrong with this code.
I was having a bit of JSDoc trouble with it before, so maybe it’s something like that?
Thanks guys.