Skip to main content
Known Participant
Jul 28, 2022 7:14 AM UTC
Solved

Access to First, Previous, Next, Last record on summary tab

For accessing the next and previous records from the summary page view i have been applying the following logic on primary key and its giving me the required result of giving the previous and last records correctly.

a!queryEntity(
entity: cons!TT_TimesheetLog_Cons,
query: a!query(
pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: 1,
sort: a!sortInfo(
field: "id",
ascending: if(ri!fetchingPrevious, false(), true())
)
),
filter: a!queryFilter(
field: "id",
operator: if(ri!fetchingPrevious, "<", ">"),
value: ri!currentPrimaryKey
)
)
).data.id

now the situation is following:

-like the next and previous buttons, I also want the last and first buttons which should take me to the first and last records in the grid, e.g. if i have 100 records the first button should open the first record summary view tab and the last button should open the 100th record. Currently I am not able to do that.

-also if i am on the last record lets say 100 i want the last button to be disabled in that scenario, similarly if i am on first record i want the first button to be disabled.

How can i achieve these two functionalities?

harshitb6843
Brainy
Jul 28, 2022 8:34 AM UTC

a!queryEntity(
  entity: cons!TT_TimesheetLog_Cons,
  query: a!query(
    pagingInfo: a!pagingInfo(
      startIndex: 1,
      batchSize: 1,
      sort: a!sortInfo(
        field: "id",
        ascending: if(
          or(ri!fetchingPrevious, ri!position = "LAST"),
          false(),
          true()
        )
      )
    ),
    filter: a!queryFilter(
      field: "id",
      operator: if(
        or(ri!position = "FIRST", ri!position = "LAST"),
        "=",
        if(ri!fetchingPrevious, "<", ">")
      ),
      value: ri!currentPrimaryKey
    )
  )
).data.id

7 replies

harshitb6843
Brainy
Jul 28, 2022 7:20 AM UTC

When you want to open the first record, simply pass the operator as "=", start index as 1. Done. 
When you want to open the last record, pass the operator as "=", the startIndex as the total count from the query, or sort the data descending and pass the start index as 1. 

Known Participant
Jul 28, 2022 7:33 AM UTC

can you show it with some exmaple?

harshitb6843
Brainy
Jul 28, 2022 8:34 AM UTC

a!queryEntity(
  entity: cons!TT_TimesheetLog_Cons,
  query: a!query(
    pagingInfo: a!pagingInfo(
      startIndex: 1,
      batchSize: 1,
      sort: a!sortInfo(
        field: "id",
        ascending: if(
          or(ri!fetchingPrevious, ri!position = "LAST"),
          false(),
          true()
        )
      )
    ),
    filter: a!queryFilter(
      field: "id",
      operator: if(
        or(ri!position = "FIRST", ri!position = "LAST"),
        "=",
        if(ri!fetchingPrevious, "<", ">")
      ),
      value: ri!currentPrimaryKey
    )
  )
).data.id