Forum Discussion

AngelRodriguez's avatar
AngelRodriguez
Qrew Assistant Captain
2 years ago

Question About Creating One Record (Combined) inside a For Each Loop

I'm working with two tables, a Parts Task table (parent), and a Task Activities table (child).  Each activity represents a part number shipped from a specific location, e.g. MISC-1-A10, MISC-1-A20, etc. Here are the steps, via a Pipeline, I'm trying to achieve but I'm stuck on step D:

 

  1. When the shipping task is completed the Pipeline is triggered.

  2. Create a new receiving task from the completed shipping task in step A.

  3. Search for all related activities for the task in step A.

  4. For each activity I would normally create a copy from step C and append that to the task created in step B, but in this case, I want to create one combined activity for all activities with the same part number and combine their 'Quantity Shipped'. 

    1. In the attached image, you'll see we have three line items for '2525…., Fake Part'. With a combined 'Quantity Shipped' of 10.

    2. I'd like to merge all three line items into one receiving activity of 10 shipped.

    3. Is there a way to do this with a Pipeline or do I need to separate the activity creation into a webhook or something similar?



------------------------------
AR
------------------------------

  • Just Brainstorming 

    IF this table is not very big , you might be able to use formula query out all instance of 2525/test,Fake Part along with their Record ID in a field , then maybe have a criteria to get a checkbox in place for only 1of them  (earliest [Record ID#]) , another for sum. 

    Then a pipeline can trigger which deletes all the non checkboxes items and creates a record

    part [Record ID#] Sum Formula Query Chebox
    2525/test,Fake 3 10 3,5,6 Yes
    2525/test,Fake 5 0 False
    2525/test,Fake 6 0 False


    ------------------------------
    Prashant Maheshwari
    ------------------------------
  • AngelRodriguez's avatar
    AngelRodriguez
    Qrew Assistant Captain

    I came up with a workaround for this.  It doesn't iterate over the matching activities (with the same part number).  Instead, I just ignore these matches (Shipping from multiple locations), since I have everything I need in the first instance (original) of the part.  Since the original part is the only line item (matching part - matches the other two activities by part number but shipping from another location) that contains a quantity requested, I would include a condition in the 'Search records' step of the Pipeline to exclude anything that has a blank or null quantity requested.  Since my original part uses a formula query field that already combines the total quantity shipped of all like parts, I can use that to create my receiving activity.  Keep in mind that the 'shipping from' location in my receiving task does not matter on the receiving end as our ordering locations only care that they receive X quantity of parts.  They're not concerned about the location from where the part was shipped.

    This doesn't solve the technical question of iterating over records with the same part number and somehow combining them, but for this specific dilemma, I was able to create a workaround to the issue. 



    ------------------------------
    AR
    ------------------------------