Forum Discussion

AmyGosz1's avatar
AmyGosz1
Qrew Trainee
9 days ago

Pipeline to create record and populate a date field

I created a pipeline to create a record in a table (Statuses) after a record in another table (Masters) is created. For each Master record created I need 4 Status records created - each with a due date at 3,6,9, and 12 months after the expected start date noted in the Master. I have tried several formulas but am unable to get the right formula. The Expected Start Date in the Masters table is FID 13. If that date is 11-1-2024, how do I write the Status Due Date pipeline formula(s) to create a record with the due date of 2-1-2025 (and subsequently 5-1-2025, 8-1-2025 and 11-1-2025)?  Dates will be different for each Master so I can't plug in hard dates.

Can i create all 4 records in the same pipeline by adding additional 'create' steps? Or do I need 4 separate pipelines?

  • AmyGosz 

    In the past I have use this technique to create a variable number of child records.  

    I create an Admin Record in a table with just 1 record to record the Record ID# of the Focus Masters.  I create a relationship where One Masters has many Admins  and I look up any fields which will be required to determine how many Child record will need to be created from Masters down to the admin record.

    Then I create a helper table say with 100 records in it.  Using a formula based on the the native Record ID field or another field that I populate I make sure that there is a field numbered 0 to 100. Call this [Month#].

    Then make a formula field to calculate the first day of the month based on a starting date plus the number of Months in [Month#].

    I then create a formula field with a value of 1, to link to the Admin record and lookup any fields I need to determine if the month is valid to be imported into Statuses. 

    Then you will have to use your formula skills to come up with a checkbox formula Field to determine which of those 100 future months are valid to be created a a status record.

    So then the last step would be to have a button which initiates a pipeline which would set the admin record on the focus master thus causing the helper table records to auto check box if they are valid to be created as a status record and then have the pipeline look for those valid records and create status children. 

     

  • DonLarson's avatar
    DonLarson
    Qrew Commander

    Amy,

    Since this is linear, I would use two Pipelines and this architecture

     

    Pipeline One will fire when the Master Timeline record is created.

    It creates one Time Status record where Due Date =

    {{ a.start_date.replace(day=1) + time.delta(months=3) }} 

    Pipeline Two will fire when a Timeline Status record is created

    Step B is to Search for the Master Timeline record

    Now you need some If Conditions

    If # of Status Records  < # Required

    Then Create another Timeline Status Record

    where Due Date =

    {{ a.max_due_date.replace(day=1) + time.delta(months=3) }}

    If # of Status Records  = # Required

    Then Create another Timeline Status Record

    where Due Date =

    {{ a.completion_date + time.delta(days=1) }}

    If # of Status Records  > # Required

    Then END

    Creating that final Timeline Status record will fire Pipeline #2 again but it ENDS and nothing else happens.

     

    • DonLarson's avatar
      DonLarson
      Qrew Commander

      Max Due Date is a Summary field as well.  It keeps going up as Timeline Status records are added.

  • DonLarson's avatar
    DonLarson
    Qrew Commander

    Amy,

    I would suggest target it this way.

    Step A is when a Master Record is Created

    Step  B is to Search the Status Table

    Step C is inside the loop from the Search

    This will let you add statuses or change the duration for any status with out changing your Pipeline

    {{ a.start_date.replace(day=1) + time.delta(months='b.duration') }}

    • AmyGosz1's avatar
      AmyGosz1
      Qrew Trainee

      HI Don…I am trying to understand the formula you shared. It actually got me to thinking about some of the action items and actual durations possible. Technically, the budget line is the starting point. When a budget line with ‘budget type’ = 1 or 5 (action item therefore an update is needed), then the ‘Master Timeline’ record is created. When that Master Timeline record is created, then the Timeline Status records get created.

      However, 4 updates over a one year period are not always needed as a budget item might be completed in less than one year. Or, maybe more are needed if completion date is more than one year.

      I can create a duration field, but how does that value work in your formula? If the duration is 6 months, then 2 updates (one at 3 months and one at 6 months) are needed. If the duration is 5 months, then 2 updates are needed (one at 3 months and one at the end). If the duration is over 12 months, I would like to have additional updates created. Users can create additional updates using the ‘add’ button, but creating them via a pipeline avoids human error of one or more updates being missed.

      For duration, I could create a formula field that looks at the # of month between start and completion and then divide that by 4. That would be the # of update records needed.

      Any additional help you can throw my way is greatly appreciated.

      • DonLarson's avatar
        DonLarson
        Qrew Commander

        Amy,

        Great question.    If I understand your business requirements, which is a BIG if,  your Time Line Status records are evenly spaced in 3 month intervals from the Start Date until the end.

        So if you had some that went 61 months, you need to create 21 records.   The first 20 are three months apart and the last one would be one month after #20.

        Am I right? 

         

  • AmyGosz1's avatar
    AmyGosz1
    Qrew Trainee

    I did find the answer with QB Junkie. Here is the formula and it worked.

    {{ a.expected_implementation_date.replace(day=1) + time.delta(months=3) }} with 3 being the variable for each month needed. This also makes the date the 1st of each of those months specified.

    I was also able to do all 4 record creation steps within the same pipeline.