Skip to main content
July 28, 2022
Solved

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

  • July 28, 2022
  • 7 replies
  • 0 views

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?

Best answer by harshitb6843

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
July 28, 2022

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. 

July 28, 2022

can you show it with some exmaple?

harshitb6843
July 28, 2022

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