Forum Discussion

dkinsley's avatar
dkinsley
Creator II
2 years ago
Solved

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

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

    [embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:bdddaaf2-822e-42f9-88df-16bac7f4c1d8:type=csharp&text=var%20inn%20%3D%20this.getInnovator%28%29%3B%0D%0A%0D%0Avar%20parts%20%3D%20inn.newItem%28%22Part%22%2C%22get%22%29%3B%0D%0Aparts%20%3D%20parts.apply%28%29%3B%0D%0AList%3Cstring%3E%20relPartList%20%3D%20new%20List%3Cstring%3E%28%29%3B%0D%0AList%3Cstring%3E%20sourcePartList%20%3D%20new%20List%3Cstring%3E%28%29%3B%0D%0Afor%20%28int%20i%20%3D%200%3B%20i%20%3C%20parts.getItemCount%28%29%3B%20i%2B%2B%29%7B%0D%0A%20%20var%20currPart%20%3D%20parts.getItemByIndex%28i%29%3B%0D%0A%20%20var%20bomRel%20%3D%20inn.newItem%28%22Part%20BOM%22%2C%22get%22%29%3B%0D%0A%20%20bomRel.setProperty%28%22source_id%22%2CcurrPart.getID%28%29%29%3B%0D%0A%20%20bomRel%20%3D%20bomRel.apply%28%29%3B%0D%0A%20%20%2F%2Fthis%20is%20each%20relationship%20with%201%20child%20part%0D%0A%20%20if%20%28bomRel.getItemCount%28%29%20%3D%3D%201%29%7B%0D%0A%20%20%20%20%2F%2Fthis%20related_id%20is%20the%20child%20Part%2C%20bomRel.getID%28%29%20would%20actually%20get%20us%20the%20ID%20of%20the%20BOM%20Relationship.%0D%0A%20%20%20%20%2F%2FrelPartList.Add%28bomRel.getProperty%28%22related_id%22%29%29%3B%0D%0A%20%20%20%20%2F%2FWhat%20we%20want%20is%20to%20get%20the%20actualy%20child%20part%20which%20is%20the%20related_id%20of%20the%20BOM%20relationship%0D%0A%20%20%20%20var%20relPart%20%3D%20inn.getItemById%28%22Part%22%2CbomRel.getProperty%28%22related_id%22%29%29%3B%0D%0A%20%20%20%20%2F%2Fnow%20that%20we%20have%20access%20to%20the%20related%20part%2C%20we%20can%20simply%20query%20the%20part%20number%0D%0A%20%20%20%20var%20itemNumber%20%3D%20relPart.getProperty%28%22item_number%22%2C%22%22%29%3B%0D%0A%20%20%20%20sourcePartList.Add%28%24%22Part%20Num%3A%20%7BcurrPart.getProperty%28%22item_number%22%2C%22%22%29%7D%2C%20Related%20Part%20Num%3A%20%7BitemNumber%7D%22%29%3B%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0Areturn%20inn.newResult%28%22Parts%20with%201%20Item%20in%20EBOM%3A%5Cn%22%20%2B%20String.Join%28%22%5Cn%22%2CsourcePartList%29%29%3B]

    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. 

4 Replies

  • asebastian's avatar
    asebastian
    Community Manager

    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

    • dkinsley's avatar
      dkinsley
      Creator II

      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

       

      • asebastian's avatar
        asebastian
        Community Manager

        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.

        [embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:bdddaaf2-822e-42f9-88df-16bac7f4c1d8:type=csharp&text=var%20inn%20%3D%20this.getInnovator%28%29%3B%0D%0A%0D%0Avar%20parts%20%3D%20inn.newItem%28%22Part%22%2C%22get%22%29%3B%0D%0Aparts%20%3D%20parts.apply%28%29%3B%0D%0AList%3Cstring%3E%20relPartList%20%3D%20new%20List%3Cstring%3E%28%29%3B%0D%0AList%3Cstring%3E%20sourcePartList%20%3D%20new%20List%3Cstring%3E%28%29%3B%0D%0Afor%20%28int%20i%20%3D%200%3B%20i%20%3C%20parts.getItemCount%28%29%3B%20i%2B%2B%29%7B%0D%0A%20%20var%20currPart%20%3D%20parts.getItemByIndex%28i%29%3B%0D%0A%20%20var%20bomRel%20%3D%20inn.newItem%28%22Part%20BOM%22%2C%22get%22%29%3B%0D%0A%20%20bomRel.setProperty%28%22source_id%22%2CcurrPart.getID%28%29%29%3B%0D%0A%20%20bomRel%20%3D%20bomRel.apply%28%29%3B%0D%0A%20%20%2F%2Fthis%20is%20each%20relationship%20with%201%20child%20part%0D%0A%20%20if%20%28bomRel.getItemCount%28%29%20%3D%3D%201%29%7B%0D%0A%20%20%20%20%2F%2Fthis%20related_id%20is%20the%20child%20Part%2C%20bomRel.getID%28%29%20would%20actually%20get%20us%20the%20ID%20of%20the%20BOM%20Relationship.%0D%0A%20%20%20%20%2F%2FrelPartList.Add%28bomRel.getProperty%28%22related_id%22%29%29%3B%0D%0A%20%20%20%20%2F%2FWhat%20we%20want%20is%20to%20get%20the%20actualy%20child%20part%20which%20is%20the%20related_id%20of%20the%20BOM%20relationship%0D%0A%20%20%20%20var%20relPart%20%3D%20inn.getItemById%28%22Part%22%2CbomRel.getProperty%28%22related_id%22%29%29%3B%0D%0A%20%20%20%20%2F%2Fnow%20that%20we%20have%20access%20to%20the%20related%20part%2C%20we%20can%20simply%20query%20the%20part%20number%0D%0A%20%20%20%20var%20itemNumber%20%3D%20relPart.getProperty%28%22item_number%22%2C%22%22%29%3B%0D%0A%20%20%20%20sourcePartList.Add%28%24%22Part%20Num%3A%20%7BcurrPart.getProperty%28%22item_number%22%2C%22%22%29%7D%2C%20Related%20Part%20Num%3A%20%7BitemNumber%7D%22%29%3B%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0Areturn%20inn.newResult%28%22Parts%20with%201%20Item%20in%20EBOM%3A%5Cn%22%20%2B%20String.Join%28%22%5Cn%22%2CsourcePartList%29%29%3B]

        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.