Forum Discussion

MCAdmin's avatar
MCAdmin
Qrew Member
3 years ago

Pipeline Jinja template expression

Hello, I am looking for a jinga expression/syntax which could help me validate the sum(Field-1) > NN value in a step using if condition.  

Below is the pipeline steps:
Table-B structure
Record ID#, country, Qty issued
1, UK, 20.5,
2, UK, 30
3, UK, 30.8

Pipeline

Step-A
     When the record is created in table-A
Step-B
     Search records in Table-B  where b.country =  "UK"
     If sum(qty) >= 100
               Step-C - Create record in Table-C 
     Else
              Step-D - Create record in Table-D

I want the jinga expression to be added in step-B post search is returned to check the sum(qty) and compare if it exceed or equals 100







------------------------------
MC 
------------------------------

3 Replies

  • @MC Admin You are on the right track.

    If your ​'no_of_days' attribute/field is required and will not have any null values you can use this approach:

    {{ (d|sum(attribute='no_of_days')) >= 100 }}

    However, if there may be null values in the 'no_of_days' field a different approach is necessary.

    {% set total = namespace(value=0) %}
    {%
    for r in d %}
    {%
    set total.value = total.value + (r.no_of_days|default(0, true)) %} {% endfor %}
    {{ total.value >= 100 }}


    The above creates a 'total' variable with an initial value of 0. Then loops through the records found in Step D adding them together, while setting a default value of 0 if null. Then it evaluates it against the value of 100 for the condition.

    To learn more about using Jinja in Pipelines I suggest taking the "Intro to Jinja for Pipelines" course. It includes a Library of Jinja references for Pipelines including approaches such as this.  https://www.quickbasejunkie.com/intro-to-jinja

    Let me know if this works and what approach ended up doing the job. πŸ‘

    -Sharon

    ------------------------------
    Quick Base Junkie
    ------------------------------
    • MCAdmin's avatar
      MCAdmin
      Qrew Member
      Thank you Sharon for this master piece code on jinga. This worked perfectly.  Hats off to you.

      I also noticed that the search results from step-D are not sequenced and they come in random order. I would like to fetch the search results orded by a start date in ascending order so I can match with a date from step-A.  

      Regards
      Babi

      ------------------------------
      MC Admin
      ------------------------------
      • Quick_BaseJunki's avatar
        Quick_BaseJunki
        Qrew Captain
        @MC Admin unfortunately I'm not aware of any way to control the order using the 'native' Quickbase search/query step.

        However, if you use the Fetch & Iterate JSON steps with the RESTful API you can create your own query specifying the sort order in the options.

        https://developer.quickbase.com/operation/runQuery


        This is a much more complex approach and not something I can get into here, but the QB documentation above is pretty good and the Trending Data with Pipelines and the RESTful JSON API video in the university appears to cover these channels.

        -Sharon
        ​

        ------------------------------
        Quick Base Junkie
        ------------------------------