Group a record list by date

Certified Associate Developer

Hello, 
I'm currently building an audit history for my job. The way our client wants the history displayed is grouped by the date that the history action is created on. So that the list sometimes displays 1 action per timestamp and sometimes 2 or 3 actions by timestamp. We have found a way to do this but it is complicated. I get all the values in the histActionOn, then I uses union() to get only the unique values. From this point I can do more complex indexing to organize all the actions by date, or I can throw a a!queryRecordType() in a for loop and filter it by the histActionOn field. This gets exactly what I need. A record list with actions separated by date and time, but it's incredibly inefficient as it puts a query in a for loop. I'm sure there's a way to group all the actions by unique dates, but I don't know a way at this point. 

Any thoughts?

Thank you

Jason

  Discussion posts and replies are publicly visible

Parents Reply
  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    so the problem there is that it grabs all the dates, and doesn't eliminate duplicate dates. I'm sure I'm missing another step, but I ended up querying the record type, grabbing the date field I wanted in local variable. I then applied union() to it to get all the unique dates. After that I ran the unique dates as the items in a for loop, and then created another local variable where I indexed the record query based on each unique date. this got me all the record entries based on the unique dates. 

Children
  • 0
    Certified Lead Developer
    in reply to Jason

    OK. There is even a design pattern in the interface designer that implements this. It is the "Event Timeline".

    Keep in mind to not load too much data and implement paging and search to allow navigation.

    https://appian.rocks/2023/07/24/universal-paging/

  • 0
    Appian Employee
    in reply to Jason

    I think the key is that you don't want to just query a selection of the fields, but instead you would likely want to aggregate the data. Here's an example of aggregating the data by a field: docs.appian.com/.../Query_Recipes.html

  • 0
    Certified Associate Developer
    in reply to Peter Lewis

    Yes, I want to aggregate everything under the unique dates that cations were taken. Essentially I want the modifiedDate field to be a sort of pk in which all records are organized under that date. While Appian does allow me to aggregate based on the date I want, I can't condense the data so that all records that happen on one date, are nested under that one unique date. At least, I can't seem to do this without indexing and using wherecontains() and all that. 

    example:
    i query a record type and get only the date fields
    {dateAndTime1, dateAndTime2, dateAndTime3, dateAndTime4, dateAndTime4}

    I apply union() to eliminate duplicates resulting in {dateAndTime1, dateAndTime2, dateAndTime3, dateAndTime4}

    I then take that list and use index to aggregate all the records under those dates:

    forEach(
        items: local!uniqeDates,
        expression: index(local!recordQuery, wherecontains(fv!item, local!recordQuery.modifiedDate))
    ),

    which outputs something like:

        uniquedate1
                 record
        uniquedate2
                 record
        uniquedate3
                 record
        uniquedate4
                 record
                 record


    uniqueDate4 has two records because two modifications were made at that exact date and time. 


    again, I am able to produce what I want, I just want to know if there is an easier way to do this using built in functionality for record types. 

  • 0
    Appian Employee
    in reply to Jason

    Ahhhh I see what you mean - the key is that you still want to keep the list of the original data that you are grouping by. Unfortunately I'm not sure there's another way that is that much better - I think the approach you mentioned is probably the right way.