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,

    here is the method run on the onBeforeDelete event: Its used to ser/delete some properties on specific parts and is used as a server event on two different relationship itemTypes.

    Innovator inn=this.getInnovator();
    String VesselId="";

    //Set Vessel id based on which relationship is being updated.

    switch(this.getType())
    {
    case "VE_Vessel_System":
    VesselId= (this.getAction().Equals("delete"))?"":this.getProperty("source_id");
    break;
    case "Part BOM":
    Item SourcePart=inn.newItem("Part","get");
    SourcePart.setID(this.getProperty("source_id"));
    SourcePart.setAttribute("select","classification,ve_vessel");
    SourcePart=SourcePart.apply();
    if(SourcePart.getProperty("classification","").Equals("SYSTEM"))
    VesselId=(this.getAction().Equals("delete"))?"":SourcePart.getProperty("ve_vessel","");
    else
    VesselId="";
    break;
    default:
    VesselId="";
    break;

    }

    if(VesselId.Equals("") && this.getAction().Equals("add"))
    return this;

    //Call Procedure to set Vessel Property through out hte structure.
    Item ProcedureCall = this.getInnovator().newItem("SQL", "SQL PROCESS");
    ProcedureCall.setProperty("name", "VE_SetVesselProperty");
    ProcedureCall.setProperty("PROCESS", "CALL");
    ProcedureCall.setProperty("ARG1", this.getProperty("source_id"));
    ProcedureCall.setProperty("ARG2",VesselId);

    return ProcedureCall.apply();

  • Hi BerntOve

    Can you update the onBeforeDelete Event with below code. Modifications are highlighted in bold

    Innovator inn=this.getInnovator();
    String VesselId="";

    //Set Vessel id based on which relationship is being updated.

    switch(this.getType())
    {
    case "VE_Vessel_System":
    VesselId= (this.getAction().Equals("delete"))?"":this.getProperty("source_id");
    break;
    case "Part BOM":
    Item getBOMInfo = inn.newItem("Part BOM","get");
    getBOMInfo.setID(this.getID());
    getBOMInfo.setAttribute("select","source_id");
    getBOMInfo = getBOMInfo.apply();

    Item SourcePart=inn.newItem("Part","get");
    SourcePart.setID(getBOMInfo.getProperty("source_id"));
    SourcePart.setAttribute("select","classification,ve_vessel");
    SourcePart=SourcePart.apply();
    if(SourcePart.getProperty("classification","").Equals("SYSTEM"))
    VesselId=(this.getAction().Equals("delete"))?"":SourcePart.getProperty("ve_vessel","");
    else
    VesselId="";
    break;
    default:
    VesselId="";
    break;

    }

    if(VesselId.Equals("") && this.getAction().Equals("add"))
    return this;

    //Call Procedure to set Vessel Property through out hte structure.
    Item ProcedureCall = this.getInnovator().newItem("SQL", "SQL PROCESS");
    ProcedureCall.setProperty("name", "VE_SetVesselProperty");
    ProcedureCall.setProperty("PROCESS", "CALL");
    ProcedureCall.setProperty("ARG1", this.getProperty("source_id"));
    ProcedureCall.setProperty("ARG2",VesselId);

    return ProcedureCall.apply();

    Thank You

    Gopikrishnan R

  • Hi,

    workd now. Thanks, but not sure why modifying this part fixed the error.

    Bernt Ove

  • Hi BerntOve,

    When the Part BOM is deleted from UI, then it has the context item and able to get the source ID but when we are deleting through action we don't have the source id information and only we have the ID of the Part BOM. so, using that we are fetching the source ID and passing that as input.