Forum Discussion

DwightMunson1's avatar
DwightMunson1
Qrew Assistant Captain
2 years ago

Pipeline Jinja Issues

Hello Quickbase Community!

I'm having issues with a pipeline. 

Step A: Quickbase Channel - Quickbase API - Make a Request

Essentially, I query data in a table and get back some JSON data. This step works completely fine. 

Step B (the problem step): Quickbase Channel - Quickbase API - Make a Request

This request is to post data to a test table for now. I'm trying to run a for loop on the data. I'm eventually going to incorporate the myTimeStop variable, but it can be ignored for now. I'm trying to iterate through the data, adding a line for each one, and keeping a running total for row '33'.

This works, but it's still resetting the runningTotal to 0.0 in each loop for some reason. Table ID redacted.

{% set myDataSet = "myTableID" %}
{% set myTimeStop = 5.0 | float %}
{% set runningTotal = 0.0 | float %}
{
    "to": "{{myDataSet}}",
    "data": [
        {% for row in a.json.data %}
        {% set runningTotal = runningTotal + row['33'].value %}
        {
            "6": {
                "value": "{{row['36'].value}}"
            },
            "7": {
                "value": "{{row['8'].value}}"
            },
            "8": {
                "value": "{{row['13'].value}}"
            },
            "9": {
                "value": "{{row['33'].value}}"
            },
            "10": {
                "value": "{{runningTotal}}"
            }
        }
        {% if not loop.last %},{% endif %}
        {% endfor %}
    ]
}

I've tried this, but it gives me a vague error. It's pretty much the same as the top, but I'm appending each line to the list as later I want to iterate through the data until I hit the timestop variable and then add that list to Quickbase. 

{% set myDataSet = "myTableID" %}

{% set myTimeStop = 5.0 | float %}
{% set runningTotal = 0.0 | float %}

{% set data = [] %}

{% for row in a.json.data %}
    {% set runningTotal = runningTotal + row['33'].value %}
    {% set item = {
        "6": {"value": row['36'].value},
        "7": {"value": row['8'].value},
        "8": {"value": row['13'].value},
        "9": {"value": row['33'].value},
        "10": {"value": runningTotal}
    } %}
    {% do data.append(item) %}
{% endfor %}

{
    "to": "{{myDataSet}}",
    "data": {{data|to_json}}
}

I'm just not understanding why it doesn't like the second variation. It passes the test initially, but when run gives a vague "Something went wrong executing a step. Try modifying your pipeline."

Also, not understanding why in the first one it's not actually keeping a running total. 



------------------------------
Dwight Munson
------------------------------

6 Replies

  • DwightMunson1's avatar
    DwightMunson1
    Qrew Assistant Captain

    For the second bit, I've also tried:
    {% set data = data.append(item) %}

    and

    {% set _ = data.append(item) %}

    and

    {{data.append(item)}}

    I've also tried: 

    {
        "to": "{{myDataSet}}",
        "data": {{data|tojson}}
    }

    and

    {
        "to": "{{myDataSet}}",
        "data": {{ data | tojson }}
    }



    ------------------------------
    Dwight Munson
    ------------------------------
    • DonLarson's avatar
      DonLarson
      Qrew Commander

      Dwight,

      I am no Jinja or Python expert, however I remember reading somewhere in a Python resource about declaring variables inside and outside of a loop.   You have defined Running Total twice and there is a voice in my head saying that your problem lies there.

      The two best resources for Jinja here are @Doug Henning or @Prashant Maheshwari 



      ------------------------------
      Don Larson
      ------------------------------

      • DwightMunson1's avatar
        DwightMunson1
        Qrew Assistant Captain

        This worked for me for the running total. Now I'm trying to figure out a while loop for it to only iterate up to the myTimeStop.

        {

        {% set myDataSet = "myTableID" %}

        {% set myTimeStop = 5.0 %}

        {% set runningTotal = namespace(val=0.0) %}

            

        "to": "{{myDataSet}}",

        "data":[

         

            {% for row in (a.json.data) %}

            {

                {% set runningTotal.val = runningTotal.val + row['33'].value %}

                "6":{          

                        "value": "{{row['36'].value}}"

                },

                "7":{          

                        "value": "{{row['8'].value}}"

                },

                "8":{           

                        "value": "{{row['13'].value}}"

                },

                "9":{          

                        "value": "{{row['33'].value}}"

                },

                "10":{          

                        "value": "{{runningTotal.val}}"

                }

            }

            {% if loop.last == false %},{% endif %}

            {%- endfor %}

        ]

        }



        ------------------------------
        Dwight Munson
        ------------------------------