Forum Discussion

TimD's avatar
TimD
Qrew Trainee
2 years ago

Last iteration of the Search step

How can i identify that the last iteration of the Search step?

On the last iteration, i would like it to stamp a field but I havent found a way to do this through jinja (at least in the way i want it)

this works in getting me the highest record id (which is my default sort for the table):

{% set highest = a|max(attribute="id") %}
{{highest.id}}

and i can use this in the look up step and find the last iteration of the loop, however, i would like to not have to do this part.

on the for each after the Search step, i am trying this:

{% set highest = a|max(attribute="id") %}
{% if a.id == highest.id %}
    {{TRUE}}
{% endif %}

but i just keep getting a TypeError: 'Record' object is not iterable.

does anyone happen to know how to stamp a field in a for each loop only when it is the last iteration of the loop?

Thank you!



------------------------------
Tim D
------------------------------
  • This is from one of my working jinja code , I believe loop.last is what you want , you will loop.last==true and then your code 

            {% for i in range(a.enquiry|int) %}        

              "22":  { "value" : "{{loop.index}} of {{a.enquiry|int}}" },
              "6":  { "value" : "{{a.id}}" }            
    }
                                        
    {% if loop.last == false %},{% endif %}
    {% endfor %}



    ------------------------------
    Prashant Maheshwari
    ------------------------------
    • TimD's avatar
      TimD
      Qrew Trainee

      at which step do you do that? i assume you do it outside of the for loop?

      I'm gonna try it in when i get back on that task but when i've tried to loop it outside of the for loop, after the Search step, i get an error like this:

      Query step produced too many items to allow inline indexed access. Please use a LOOP construct



      ------------------------------
      Tim D
      ------------------------------
      • PrashantMaheshw's avatar
        PrashantMaheshw
        Qrew Captain

        Tim, 
        Some confusion

        • The code I have given is the loop
        • Assuming you've done a search in previous step , you can always refer to the max value of any attribute the way you've already specified with {{ a|map(attribute='id')|max }}. You don't need a loop for this 
        • If you want the loop to work and do on the last step you can use what I provided . For example below prints the highest mobile number and it prints the last mobile number as found by the search. Earlier code was if not loop.last , this is loop.last
        • {{ a|map(attribute='mobile')|max}}
          {% for i in range(a|length) %}        
          {% if loop.last %}{{a.mobile}}{% endif %}
          {% endfor %}
          



        ------------------------------
        Prashant Maheshwari
        ------------------------------