How to get part numbers from part IDs

I have a query that returned a large number of part IDs that have a single eBOM item ID. 

To get the part IDs converted to part numbers I used the AML "idlist" function. 

How can I get the part BOM IDs converted to part numbers and keep the relationship with the part number they belong to?

Note: My IDs are a long string separated by commas.

Don

Parents
  • Hi Don,

    Just curious for more context here. Is this an operation you're attempting to run once, or is it something you'll have to do routinely? The solution I gave you previously works well for a one off query, but might not work well at scale or for repeated use.

    If you give me a little context I can hopefully help with a solution that better fits your needs.

    Thanks,

    AJ

  • 0 オフライン in reply to AJ Sebastian

    Hi AJ,

    With help, the script you provided has been modified to include the single eBOM item ID as follows:

    var inn = this.getInnovator();

    var parts = inn.newItem("Part","get");
    parts = parts.apply();
    List<string> relPartList = new List<string>();
    List<string> sourcePartList = new List<string>();
    for (int i = 0; i < parts.getItemCount(); i++){
      var currPart = parts.getItemByIndex(i);
      var bomRel = inn.newItem("Part BOM","get");
      bomRel.setProperty("source_id",currPart.getID());
      bomRel = bomRel.apply();
      if (bomRel.getItemCount() == 1){
        relPartList.Add(bomRel.getProperty("related_id"));
        sourcePartList.Add($"Part ID: {currPart.getID()}, Related Part ID: {bomRel.getID()}");
      }
    }

    return inn.newResult("Parts with 1 Item in EBOM:\n" + String.Join("\n",sourcePartList));

    Now my results are in this format:

    Part ID: 858130EDB8604EE394BD8937B2B95A22, Related Part ID: 7345A108DF2C42A7A9E869A39DD6FA2D

    Part ID: 028128A1047846448C354C1E02FBC310, Related Part ID: 6EA253E00BC546AEB19014414F7C021F</Result>

    Prior, with your script, I took the resulting string of comma separated part IDs and used the AML function idlist as you suggested. I was going to try and get the related eBOM part numbers the same way if they return in the same order as the part numbers.  I have over 9,000 parts. The IDs don't mean anything to the Engineers.  I need to get these IDs converted to part numbers and there are too many to do it manually - maybe there is an easier way?

    Thank you,
    -Don

     

  • +1 オフライン in reply to dkinsley

    If I'm understanding you correctly here, you're looking for the part numbers of all the child parts for BOM relationships with exactly 1 child.

    If you don't care about the IDs, we should be able to modify the above script very slightly to get you what you need.

    var inn = this.getInnovator();
    
    var parts = inn.newItem("Part","get");
    parts = parts.apply();
    List<string> relPartList = new List<string>();
    List<string> sourcePartList = new List<string>();
    for (int i = 0; i < parts.getItemCount(); i++){
      var currPart = parts.getItemByIndex(i);
      var bomRel = inn.newItem("Part BOM","get");
      bomRel.setProperty("source_id",currPart.getID());
      bomRel = bomRel.apply();
      //this is each relationship with 1 child part
      if (bomRel.getItemCount() == 1){
        //this related_id is the child Part, bomRel.getID() would actually get us the ID of the BOM Relationship.
        //relPartList.Add(bomRel.getProperty("related_id"));
        //What we want is to get the actualy child part which is the related_id of the BOM relationship
        var relPart = inn.getItemById("Part",bomRel.getProperty("related_id"));
        //now that we have access to the related part, we can simply query the part number
        var itemNumber = relPart.getProperty("item_number","");
        sourcePartList.Add($"Part Num: {currPart.getProperty("item_number","")}, Related Part Num: {itemNumber}");
      }
    }
    
    return inn.newResult("Parts with 1 Item in EBOM:\n" + String.Join("\n",sourcePartList));

    This returned the following output in my test system (only one instance of this occurring):

    <Result>Parts with 1 Item in EBOM:
    Part Num: test, Related Part Num: BC-BELL</Result>


    Now with over 9000 parts this method might not run too quickly, but it should get you the answer you're looking for. If this is something you're going to run routinely let me know and I can see if there's a better way to run this query more efficiently. 

Reply
  • +1 オフライン in reply to dkinsley

    If I'm understanding you correctly here, you're looking for the part numbers of all the child parts for BOM relationships with exactly 1 child.

    If you don't care about the IDs, we should be able to modify the above script very slightly to get you what you need.

    var inn = this.getInnovator();
    
    var parts = inn.newItem("Part","get");
    parts = parts.apply();
    List<string> relPartList = new List<string>();
    List<string> sourcePartList = new List<string>();
    for (int i = 0; i < parts.getItemCount(); i++){
      var currPart = parts.getItemByIndex(i);
      var bomRel = inn.newItem("Part BOM","get");
      bomRel.setProperty("source_id",currPart.getID());
      bomRel = bomRel.apply();
      //this is each relationship with 1 child part
      if (bomRel.getItemCount() == 1){
        //this related_id is the child Part, bomRel.getID() would actually get us the ID of the BOM Relationship.
        //relPartList.Add(bomRel.getProperty("related_id"));
        //What we want is to get the actualy child part which is the related_id of the BOM relationship
        var relPart = inn.getItemById("Part",bomRel.getProperty("related_id"));
        //now that we have access to the related part, we can simply query the part number
        var itemNumber = relPart.getProperty("item_number","");
        sourcePartList.Add($"Part Num: {currPart.getProperty("item_number","")}, Related Part Num: {itemNumber}");
      }
    }
    
    return inn.newResult("Parts with 1 Item in EBOM:\n" + String.Join("\n",sourcePartList));

    This returned the following output in my test system (only one instance of this occurring):

    <Result>Parts with 1 Item in EBOM:
    Part Num: test, Related Part Num: BC-BELL</Result>


    Now with over 9000 parts this method might not run too quickly, but it should get you the answer you're looking for. If this is something you're going to run routinely let me know and I can see if there's a better way to run this query more efficiently. 

Children