Deleting Part BOM relationships on Parts

Hi,

I`m currently trying to develop a function that easily deletes all Part BOM lines of a specific type (in our configuration "Purchased Parts"). All assebly parts should be left alone since in my next part of development my plan is to run the method also on these (i.e. make it recursive).

I have made an action on the Part Item that runs the following code:

Innovator inn = this.getInnovator();
Item qryItm = inn.newItem("Part", "get");
Item PartBOM_Relationship = inn.newItem("Part BOM", "get");
Item BOM_Part = inn.newItem("Part", "get");
qryItm.setID(this.getID());
PartBOM_Relationship.setRelatedItem(BOM_Part);
qryItm.addRelationship(PartBOM_Relationship);
Item partItm = qryItm.apply();

partItm.setAction("edit");

Item partRelationships = partItm.getRelationships("Part BOM");

for (int i=0; i< partRelationships.getItemCount(); i++) {

       Item part_relationship = partRelationships.getItemByIndex(i);
       Item partItem = part_relationship.getRelatedItem();

       if (partItem.getProperty("ve_classification_display", "") == "PURCHASED PART") {

             partItm.removeRelationship(part_relationship);

       }
}

partItm = partItm.apply();
return partItm;

I have checked that the if is triggered and a new generation of the part is generated, but the Part BOM relationships are still there in the new generation of the part.

I have also tried to delete the relationship item but this is not allowed in my current configuration.

What am i missing?

  • Hi BerntOve

    You can use below method to delete the Part BOM with classification "Purchased Part"

    Innovator inn = this.getInnovator();
    Item PartBOM_Relationship = inn.newItem("Part BOM", "get");
    Item BOM_Part = inn.newItem("Part", "get");
    PartBOM_Relationship.setProperty("source_id", this.getID());
    PartBOM_Relationship.setAttribute("select", "id");
    BOM_Part.setProperty("ve_classification_display", "PURCHASED PART");
    BOM_Part.setAttribute("select", "id");
    PartBOM_Relationship.setRelatedItem(BOM_Part);
    PartBOM_Relationship = PartBOM_Relationship.apply();
    List<String> idLists = new List<String>();
    for (int i = 0; i< PartBOM_Relationship.getItemCount(); i++)
    {
    idLists.Add(PartBOM_Relationship.getItemByIndex(i).getID());
    }
    if(idLists.Any())
    {
    Item PartBOM_Delete = inn.newItem("Part BOM", "delete");
    PartBOM_Delete.setAttribute("idlist", String.Join(",", idLists));
    PartBOM_Delete = PartBOM_Delete.apply();
    if(PartBOM_Delete.isError())
    {
    return inn.newError("Error Deleting the Part BOM relationship");
    }
    }
    return this;

    Thank You

    Gopikrishnan R

  • 0 オフライン in reply to Gopikrishnan

    Hi Gopikrishnan,

    Thanks for the reply. Unfortunately I`m not able to delete the Part BOM relationship item as in your example. I get the nice error "Not a single item" as the error message. Even if i expose the Part BOM itemtype in Innovator TOC and try to delete it form there i get the same message. Its a bit strange since i am an administrator and the item permission states uses the source access that states i should be able to detele the item.

    When i manually remove a Part BOM item for a Part i see that the Part BOM relationship exists still on the previsous generation of the part. The Part ItemType is of course under revision control and its possible that in my case blocks me from deleting them.

    I have also tried deleting the relationship item from AML studio as the Innovator Admin and its still the same.

    Bernt Ove

  • 0 オフライン in reply to BerntOve

    Hi

    Can you check in the Part BOM item type any method is triggered in Server Events tab On After Delete / On Before Delete events ?

  • 0 オフライン in reply to Gopikrishnan

    Hi,

    Yes, there is a OnBeforeDelete server event.

  • 0 オフライン in reply to BerntOve

    Then that method is causing some issue. for time being can you try to remove that event (change from onBeforeDelete to empty) and try running this action

  • Alternate, if you feel like the onBeforeDelete method is not required to be executed then you can trying updating the part BOM delete method with below line. Add the highlighted line in your method

    Innovator inn = this.getInnovator();
    Item PartBOM_Relationship = inn.newItem("Part BOM", "get");
    Item BOM_Part = inn.newItem("Part", "get");
    PartBOM_Relationship.setProperty("source_id", this.getID());
    PartBOM_Relationship.setAttribute("select", "id");
    BOM_Part.setProperty("ve_classification_display", "PURCHASED PART");
    BOM_Part.setAttribute("select", "id");
    PartBOM_Relationship.setRelatedItem(BOM_Part);
    PartBOM_Relationship = PartBOM_Relationship.apply();
    List<String> idLists = new List<String>();
    for (int i = 0; i< PartBOM_Relationship.getItemCount(); i++)
    {
    idLists.Add(PartBOM_Relationship.getItemByIndex(i).getID());
    }
    if(idLists.Any())
    {
    Item PartBOM_Delete = inn.newItem("Part BOM", "delete");
    PartBOM_Delete.setAttribute("idlist", String.Join(",", idLists));
    PartBOM_Delete.setAttribute("serverEvents","0");
    PartBOM_Delete = PartBOM_Delete.apply();
    if(PartBOM_Delete.isError())
    {
    return inn.newError("Error Deleting the Part BOM relationship");
    }
    }
    return this;

  • 0 オフライン in reply to Gopikrishnan

    Hi,

    thanks for the help. Disabling the OnBeforeDelete event and your code run as expected.

    Thank you very much for your help!

    Bernt Ove

  • 0 オフライン in reply to Gopikrishnan

    Hi Gopikrishnan,

    seems that the serverEvent=0 attributte only works with the action get, update, and edit. So i need to think again about the solution since in some cases the OnBeforeDelete server event is needed.

    Bernt Ove

  • 0 オフライン in reply to BerntOve

    Hi BerntOve

    You can share the onBeforeDelete event here if possible to check where it causing the issue.