Skip to main content
September 15, 2023
Question

how to get items in list based on count?

  • September 15, 2023
  • 1 reply
  • 0 views

Hi 

is there any function as if i change the count to 2 in list item of 4 it should return only 2 items..


as shown below this is list of record type ... now based on count i want to retrive items.. like if count is 2 it should give me first 2  list of record types shown below from 4 .

List of PRO Lead Documents - 2 items
PRO Lead Documents
leadId6699(Number (Integer))
workItemId:31206(Number (Integer))
createdBy:"test@scar.com"(Text)
workItemFolderId:110429(Number (Integer))
isActive:true(Boolean)
updatedBy:"test@scar.com"(Text)
documentId:110444(Number (Integer))
documentName:"_Test_Contract_2_"(Text)
updatedDt:9/14/2023 2:49 AM EDT(Date and Time)
leadDocumentLookupRefId:278(Number (Integer))
createdDt:9/14/2023 2:49 AM EDT(Date and Time)
description:""(Text)

PRO Lead Documents

leadId:6693(Number (Integer))
workItemId:31206(Number (Integer))
createdBy:"test@scar.com"(Text)
workItemFolderId:110429(Number (Integer))
isActive:true(Boolean)
updatedBy:"test@scar.com"(Text)
documentId:110446(Number (Integer))
documentName:"_Test_Contract_2_"(Text)
updatedDt:9/14/2023 2:49 AM EDT(Date and Time)
leadDocumentLookupRefId:195(Number (Integer))
createdDt:9/14/2023 2:49 AM EDT(Date and Time)
description:""(Text)

PRO Lead Documents

leadId:6692(Number (Integer))
workItemId:31206(Number (Integer))
createdBy:"test@scar.com"(Text)
workItemFolderId:110429(Number (Integer))
isActive:true(Boolean)
updatedBy:"test@scar.com"(Text)
documentId:110446(Number (Integer))
documentName:"_Test_Contract_2_"(Text)
updatedDt:9/14/2023 2:49 AM EDT(Date and Time)
leadDocumentLookupRefId:195(Number (Integer))
createdDt:9/14/2023 2:49 AM EDT(Date and Time)
description:""(Text)


PRO Lead Documents

leadId:6691(Number (Integer))
workItemId:31206(Number (Integer))
createdBy:"test@scar.com"(Text)
workItemFolderId:110429(Number (Integer))
isActive:true(Boolean)
updatedBy:"test@scar.com"(Text)
documentId:110446(Number (Integer))
documentName:"_Test_Contract_2_"(Text)
updatedDt:9/14/2023 2:49 AM EDT(Date and Time)
leadDocumentLookupRefId:195(Number (Integer))
createdDt:9/14/2023 2:49 AM EDT(Date and Time)
description:""(Text)

1 reply

mathieud0001
Brainy
September 15, 2023

Not sure if I understood this correctly but there are a couple of ways you could do this:

Probably the best way is directly in your query using the batchSize argument coupled with a sort (usually to get the most recent, you would basically sort by a datetime in descending order to get the most recent.

a!queryRecordType(
  recordType: 'recordType!{SYSTEM_RECORD_TYPE_USER}User',
  pagingInfo: a!pagingInfo(
    startIndex: 1, 
    batchSize: 2,
    sort: a!sortInfo(
      field: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{SYSTEM_RECORD_TYPE_USER_FIELD_username}username',
      ascending: false
    )
  )
)

The second best way is to do this is to convert your list to a datasubset and use the same approach as above (sort by a field and use batchSize to get the amount that you want.

a!localVariables(
  local!items: {
    a!map(
      documentId: 1,
      dateTime: datetime(2023, 09, 01)
    ),
    a!map(
      documentId: 2,
      dateTime: datetime(2023, 08, 01)
    ),
    a!map(
      documentId: 3,
      dateTime: datetime(2023, 07, 01)
    ),
    a!map(
      documentId: 4,
      dateTime: datetime(2023, 06, 01)
    ),
    a!map(
      documentId: 5,
      dateTime: datetime(2023, 05, 01)
    ),

  },
  todatasubset(
    local!items,
    a!pagingInfo(
      startIndex: 1,
      batchSize: 2,
      sort: a!sortInfo(field: "dateTime", ascending: false)
    )
  )
)

Finally, a simpler but less powerful way to do this would be with index in combination with enumerate but this would assume that your list was previously sorted beforehand.

a!localVariables(
  local!numberOfItems: 2,
  local!items: {
    a!map(
      documentId: 1
    ),
    a!map(
      documentId: 2
    ),
    a!map(
      documentId: 3
    ),
    a!map(
      documentId: 4
    ),
    a!map(
      documentId: 5
    ),
  },
  index(local!items, enumerate(local!numberOfItems)+1)
)