Forum Discussion

JamesCarr's avatar
JamesCarr
Qrew Cadet
22 days ago
Solved

Pipeline Jinja For Duration in Seconds

I would like to have a pipeline condition where nothing happens if the current time is less than or equal to 30 seconds from the value in a given field, which is a date/time field. I have tried multiple variations of jinja code and mostly get the error message:

Validation error: Incorrect template "whatever my jinja is". ValueError: invalid literal for int() with base 10: 'my_date_time_field_name'

I have tried subtracting and converting the time.now and my field to an integer before comparing to 30 for seconds, I tried using time.delta(seconds=30) and adding it to the date field then comparing it to the current time, and some other things. I get the above error each time. I would really like to do this with Jinja, if at all possible. If anyone can help, that would be greatly appreciated. I know, worse comes to worst, I can add a helper field and just work off of that,  but I am doing this for learning purposes. 

Thank you in advance to anyone who can help. 

  • That error usually happens when you don't use a loop on search step results.  If your step B is a search query, then you need to use a loop to access the results. Your step referencing B must be inside the loop.

10 Replies

  • I am mad that worked. Lol. I didn't use the loop to save a step because I knew there would only be one record resulting from the search. I started to leave it at first since it is automatically added when you insert a search step, but again, I was thinking save a step. Lesson learned. Thank you and thank everyone who was trying to help. 

    I need quickbase to fix that. There is nothing about that error that suggests that might have been the issue. 

  • Mez's avatar
    Mez
    Qrew Captain

    In pipelines you're getting/viewing/working with the raw datetime value in utc time from your datetime field. You should be able to just compare your datetime field to less than 30 seconds ago in an expression, if you're using a conditional, or even a filter. 

    In this example, if the start datetime value from the record is within 30 seconds, then follow the true path. This is within a conditional step using expression - evaluates to true:

    {% if a.start_date_time >= time.now - time.delta(seconds=30) %}
    true
    {% endif %}

    Hope this helps. 

  • I tried something very similar to this. I just now tried to do precisely what you have and it is still giving me that error message. 

  • Mez's avatar
    Mez
    Qrew Captain

    Interesting. Can you share a screenshot? 

    And, I just thought of this... you could actually just perform subtraction directly against the datetime field from time.now. With this, if you extract the seconds from the datetime object from subtracting the two values and it's less than 30, true is used, otherwise, you can print the seconds property from the subtraction; which most likely will still result in true unless the pipeline triggers and the subtraction results in zero. 

    {% if (time.now - a.start_date_time).seconds <= 30 %}
    true
    {% else %}
    {{ (time.now - a.start_date_time).seconds }}
    {% endif %}

     

  • Simply just trying to populate the value in my email sent date field into this text field using an update record step generates this error:

    Validation error: Incorrect template "{{b.email_sent_date}}". ValueError: invalid literal for int() with base 10: 'email_sent_date'

    I am assuming it just has to be converted since this is a text field I am trying to update. Even with the attempt to use the condition step, I am assuming it has to be converted. I have made attempts to do that as well, with no success. 

    • DougHenning1's avatar
      DougHenning1
      Community Manager

      That error usually happens when you don't use a loop on search step results.  If your step B is a search query, then you need to use a loop to access the results. Your step referencing B must be inside the loop.

      • JamesCarr's avatar
        JamesCarr
        Qrew Cadet

        I don't believe I am using a loop this go round so, I will double check and try that and report back tomorrow. Thanks for the suggestion. 

    • Mez's avatar
      Mez
      Qrew Captain

      This error is because int() cannot process the value being passed to it. If you would share screenshots of your run, we might be able to troubleshoot further. 

      Jinja template: #jinja-filters.int

      • JamesCarr's avatar
        JamesCarr
        Qrew Cadet

        Sorry. It was easier to just paste from my phone's clipboard last time. Crazy day today, but I wanted to ask, regarding the screen shot, how much do you need to see? Do I need to have everything expanded? The input and output where applicable, etc? Or just show you the high level steps? I didn’t know what might be too much or too little to show. If the suggestion about the loop below doesn't work out, I will gladly share whatever it takes to help troubleshoot. I appreciate everyone's input so far.