Can't create BOM with multiple parts through method

オフライン

Hello,

I'm having problems creating part relationships through a method. I have an array of arrays containing data that I want to use to generate a number of parts and their BOM relationships. The parts are being created properly but when i try to generate the BOM relationships, only the first child of each parent is added to the BOM. I'm using the loop below to try and create the BOM relations. I can see during debugging that I'm getting the right child and parent pairs, but only the first child is added to each parent.

    for (i = 2; i < (nrows-1); i++)
    {

        var p_index = par_i[i-2];
        var child = parts[i];
        var parent = parts[p_index];

        parent.setAction("edit");
        var bomItem = inn.newItem("Part BOM","add");
        bomItem.setProperty("quantity",data[i][2]);
        bomItem.setProperty("sort_order",data[i][1]);
        if (data[i][3] == "Yes")
        {bomItem.setProperty("alt_part",true);}
        bomItem.setRelatedItem(child);
        parent.addRelationship(bomItem);
        parent = parent.apply();
    }

Has anyone experienced a similar issue? How can I add multiple child parts to the BOM? I'm using Aras 11 SP12.

Best Regards

Rick