Discussions

 View Only
  • 1.  Jinja Max Value of a Field

    Posted 18 days ago
    Edited by Don Larson 18 days ago
    I have a Search step that looks at all the child records for a parent. 

    In that Search I am collecting a single Date Time Stamp Field.

    Then I am evaluating the field to get the max value using this Jinja Expression:

    {{a|max(attribute='child_table_date')}}

    It does work, picking the maximum value from all the fields in the child table.  However I am getting much more than just a date time stamp.

    --- child_table_date: 2022-11-04 00:00:00+00:00 created_at: 2022-07-26 02:40:56.063000+00:00 id: 3 last_modified_by: email: DLarson@MCFIndustries.com first_name: Don id: 56472559.bjvz last_name: Larson screen_name: DLarson_MCF record_owner: email: DLarson@MCFIndustries.com first_name: Don id: 56472559.bjvz last_name: Larson screen_name: DLarson_MCF updated_at: 2022-11-17 04:10:31.507000+00:00 ...

    I hoped to only get

    2022-11-04 00:00:00+00:00

    which I would use for another step

    Surely there is something missing from initial expression and it should not be providing everything else about the record and the value of the field.

    Anyone got a suggestion?


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


  • 2.  RE: Jinja Max Value of a Field

    Posted 18 days ago
    Following so I too can get some answers

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



  • 3.  RE: Jinja Max Value of a Field
    Best Answer

    Posted 18 days ago
    I believe max returns the whole object, so you would need to grab the single attribute from that object:

    {{ a | max(attribute='child_table_date') | attr('child_table_date') }}

    Hope that helps!

    ------------------------------
    Doug Henning
    ------------------------------



  • 4.  RE: Jinja Max Value of a Field

    Posted 15 days ago
    Doug,

    Thanks for the input.  

    That did the trick.   I have not seen the second attribute before, so I am learning something new,

    I owe you one.

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



  • 5.  RE: Jinja Max Value of a Field

    Posted 15 days ago
    Doug,

    Where did you get the answer?   

    I got the expression from here:

    https://helpv2.quickbase.com/hc/en-us/articles/4471048652308-About-Jinja-

    I substituted the field name in the attribute and got the data returned.  Your solution is much more powerful now that I think about it.

    A business case would be find the largest value for the currency field and then tell me who the record owner is.   It opens a whole host of possibilities similar to field queries.

    I would like to see what the other options are and how to use them.  I would never have guessed to put in another attribute or to abbreviate it as attr.

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



  • 6.  RE: Jinja Max Value of a Field

    Posted 15 days ago
    Hi Don, glad that worked!  That help page lists some of the supported filters but not all. At the top of that page is a link to the Jinja documentation. From there are all the Jinja built-in filters:  https://jinja.palletsprojects.com/en/2.11.x/templates/#list-of-builtin-filters.

    Since filters are chained, the output from one is the input for the other.  In your original Jinja it returned the entire record but you needed a single attribute from it thus the attr() filter.  Chaining combines multiple statements into a single:

    {{ a|max(attribute='child_table_date')|attr('child_table_date') }}

    is equivalent to:

    {% var maxrec = a|max(attribute='child_table_date') %}
    {{ maxrec | attr('child_table_date') }}

    ------------------------------
    Doug Henning
    ------------------------------