cancel
Showing results for 
Search instead for 
Did you mean: 

Snaplogic Last one before record

sravankunadi
New Contributor II

Identify the record if the entity.success = false then get the one last before record.

For example: if we have 50 records and the last record we got as false, so i want the 49 record value

image

What i am trying to do here is if the last record entity.success =false then capture the before record entity.nextpageToken

  1. If entity.success =false
    image

  2. if entity.success=true record looks like below and we would like to get the entity.nextpagetoken
    image

How can we achieve this in Snaplogic?

11 REPLIES 11

Aleksandar_A
Contributor III

Hi @sravankunadi,

You can try using Group By N Snap with Group Size set to 0 to collect all of the records in an array.

Next, you can use the following expression in a Mapper Snap to get the nextPageToken from the last record where success == true.

$group[$group.findIndex(x => x.entity.success == false) - 1].entity.nextPageToken.

Let me know if this helps you.

BR,
Aleksandar.

sravankunadi
New Contributor II

Thanks @AleksandarAngelevski for your help. Iam getting the below error

image

Hi @sravankunadi,

This would be a case if there is no response with a entity.success == false.

You can separate the process of getting the index and later you can check if the index != -1.

So, If the index != -1 then you can access the latest response with entity.success == true with $group[index-1]. And if the index == -1 then you can just use $group.pop().

BR,
Aleksandar.

sravankunadi
New Contributor II

I would like to mention one point here. I do not know when i will receive the entity.success == false it could be anywhere between 1 min and 60 min. Once i receive the entity.success==false then i would like to the flow from that nextpageToken and would like to loop untill all the records are fetched