Discussions

 View Only
  • 1.  Last iteration of the Search step

    Posted 16 days ago

    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
    ------------------------------


  • 2.  RE: Last iteration of the Search step

    Posted 15 days ago

    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
    ------------------------------



  • 3.  RE: Last iteration of the Search step

    Posted 14 days ago

    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
    ------------------------------



  • 4.  RE: Last iteration of the Search step

    Posted 13 days ago

    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[i].mobile}}{% endif %}
      {% endfor %}
      



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



  • 5.  RE: Last iteration of the Search step

    Posted 13 days ago

    I went down the jinja lane with chatGPT and learned few interesting things ! We can sort the loop also by a variable.  In your case you sort by attribute id(which might be default) and then in loop.last you an access the relevant value as well.

    {% for record in a|sort(attribute='mobile') %}
    {% if loop.last %}{{record.id}}{% endif %}
    {% endfor %}
    


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



  • 6.  RE: Last iteration of the Search step

    Posted 13 days ago

    well, unfortunately, it seems that it is dependent on the amount of records on the Search step. I was able to use the max|attribute='id' no problem when i tested on a very simple app but when i tried it on an app with larger data, it gave me the same error:

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

    I assume it has something to do with the way results are paginated?

    Anyway, just in case you had another thought:

    My use case was to do a Search step and for each of those records, I want it to update two fields. For one of those fields, i only wanted it to update when it was the last iteration of the loop. 

    What I ended up doing is: outside of the for loop, I went with a Make A Request step that queries the table with the same conditions as my Search step and then from a discussion that you were also a part of,  i take the highest record id from there (since my table settings is sorted by Record ID - low to high) and then just use look up and update the record.


    thank you for your help and insights!



    ------------------------------
    Tim D
    ------------------------------



  • 7.  RE: Last iteration of the Search step

    Posted 12 days ago

    Interesting , 

    Send me Make a request query or(and) the high quality screenshot of your pipeline .How many records are you searching btw? 

    pm at

    krishnabeads

    dot com



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