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

Parents
  • Hi Rick,

    It looks like all you are doing in that loop to parent is add children to it. If that is the case, you might want to create the relationship items directly and not as part of a Relationships node in a parent item:


    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.setProperty("source_id", parent.getID());
    bomItem.setProperty("related_id", child.getID());
    var bomResult = bomItem.apply();

    This should work pretty straightforwardly, since it is a very simple item creation everytime you loop through, no "setRelatedItem()" or "addRelationship()" stuff. 
    I know that doesn't address why your code does not work as intended, but for now it's a way you can solve your problem, I believe.

    Hope this helps.

    Cheers,

    C

Reply
  • Hi Rick,

    It looks like all you are doing in that loop to parent is add children to it. If that is the case, you might want to create the relationship items directly and not as part of a Relationships node in a parent item:


    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.setProperty("source_id", parent.getID());
    bomItem.setProperty("related_id", child.getID());
    var bomResult = bomItem.apply();

    This should work pretty straightforwardly, since it is a very simple item creation everytime you loop through, no "setRelatedItem()" or "addRelationship()" stuff. 
    I know that doesn't address why your code does not work as intended, but for now it's a way you can solve your problem, I believe.

    Hope this helps.

    Cheers,

    C

Children