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?

Parents
  • 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

    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.

  • 0 オフライン in reply to Gopikrishnan

    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();

  • 0 オフライン in reply to BerntOve

    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

  • 0 オフライン in reply to Gopikrishnan

    Hi,

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

    Bernt Ove

  • 0 オフライン in reply to BerntOve

    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. 

Reply Children
No Data