How to grab the index # of a list item to create a conditional statement in a Start - End loop

Hi,
Making myself a little nuts over here.
I have created a PDF template that uses a Start-End to loop thru a referenced list.
It works ok.
But the formatting of the pdf is a little lacking. So, I wanted to identify the 3rd item in the list and add an image to that block - this would act as a header for the 2nd page of the pdf. I can control the spacing and I know that the 3rd item will be on the top of the 2nd page.
But I canโ€™t find a way to grab the index # of the 3rd list item in order to add the conditional statement.

Below is the code snippet. Can anyone offer a solution?

"<<If: COUNT([Related Next of Kins Active]) >0>>

<<Start: [Related Next of Kins Active]>>
My Signature
<<[Signature Image]>>

<<[First Name]>> <<[Last Name]>>, <<[Relationship]>> <<[Entry Date]>>
<>

<>
<>
"

Thanks.
Penny

Solved Solved
0 7 1,145
1 ACCEPTED SOLUTION

So, update.

I tried Marcโ€™s suggestion, โ€œSELECT( [Relatedโ€ฆ][key] , [status] = โ€œActiveโ€ )โ€ but it failed to find the key - maybe because the virtual column is calling a slice.

But I did find a solution to the issue in the original solution -
it seems the, โ€œ<<If: [AdditionNextofKinId] = INDEX( [CR#].[Related Next of Kins Active] , 4 )>>โ€ wigs out if there are only 3 items in the list.
It then formats all items in the template as if they are item 4 (and its related spacing/copy).
So, I added a couple of <> statements:
<<If: COUNT([Related Next of Kins Active]) < 4>> then display regular <> / <> layout
And also
<<If: COUNT([Related Next of Kins Active]) > 3>> then use
โ€œ<<Start: [Related Next of Kins Active]>>
<<If: [AdditionNextofKinId] = INDEX( [CR#].[Related Next of Kins Active] , 4 )>>โ€ layout.

This seems to work.

View solution in original post

7 REPLIES 7

Maybe this?

<<IF: [key-column] = INDEX( [ref-column].[Related Next of Kins Active]  , 3 )>>

In general, there is no way to know the index of the START iteration, unless you insert that value into your data somehow.

My God!

It works. I would never have found that on my own. I really canโ€™t say I completely understand it but I do get the concept.

Thank you.

Hi,
Unfortunately, this does not work when the # of items changes (make an active item inactive, for example).

I have to find a good solution using appsheet webhook/json to zapier or power automate, then generate the pdf (from a template) and save the pdf to Gdrive or save the link to the pdf to Gdrive (or appsheet).

I am going to have an aneurism trying to make formatting and start/end work well in the appsheet pdf template.

Any help w 3rd parties would be appreciated.

Penny

Why not? Can you just changed both instances of
[Related...]
to
SELECT( [Related...][key] , [status] = "Active" )
?

Hi,
I am already using a slice that pulls out the โ€œactiveโ€ rows.

โ€œ<<Start: [Related Next of Kins Active]>>
<<If: [AdditionNextofKinId] = INDEX( [CR#].[Related Next of Kins Active] , 4 )>>โ€

The issue seems to be that the template wigs out when the # of active rows changes. The INDEX loses the plot and my PDF ends up with this:

The code on the template is trying to format the pages by identifying when there will be a 4th active row - then, a new template page is started.

This works well until the โ€œactive rowsโ€ changes (+/-).
Then the โ€œ<<If: [AdditionNextofKinId] = INDEX( [CR#].[Related Next of Kins Active] , 4 )>>โ€ is called for every active row on the template and includes the extra copy/spacing on the pdf for every row in the Start/End.

Resulting in this output to the pdf:

So, update.

I tried Marcโ€™s suggestion, โ€œSELECT( [Relatedโ€ฆ][key] , [status] = โ€œActiveโ€ )โ€ but it failed to find the key - maybe because the virtual column is calling a slice.

But I did find a solution to the issue in the original solution -
it seems the, โ€œ<<If: [AdditionNextofKinId] = INDEX( [CR#].[Related Next of Kins Active] , 4 )>>โ€ wigs out if there are only 3 items in the list.
It then formats all items in the template as if they are item 4 (and its related spacing/copy).
So, I added a couple of <> statements:
<<If: COUNT([Related Next of Kins Active]) < 4>> then display regular <> / <> layout
And also
<<If: COUNT([Related Next of Kins Active]) > 3>> then use
โ€œ<<Start: [Related Next of Kins Active]>>
<<If: [AdditionNextofKinId] = INDEX( [CR#].[Related Next of Kins Active] , 4 )>>โ€ layout.

This seems to work.

Ahhh.

The 4th index of a 3-length list would return blank. Appsheet has issues comparing to blank values, they generally always return TRUE.

Top Labels in this Space