CSV Template with IF for first child item

I'm trying to make a csv file that matches an invoice template needs for an accounting program.  The template calls for a csv where each row is basically the child invoice_items record.  Easy enough, but on the first row related to an invoice, (and only the first row!), details from the parent invoice are included.  I was hoping the system would just ignore it if the same parent details were just showing on each row, but no such luck.  It throws errors unless the parent info is included only in the first row of rows related to a given invoice.

So, how can I make an IF statement that will check that the current invoice_item is the first one in the list of Related Invoice_items?  Thanks in advance!

 

Solved Solved
0 7 86
1 ACCEPTED SOLUTION

Just FYI

"parent_fld1","parent_c_enum","c_id","p_id","fld1","test_t1_ref"
<<Start: SELECT(child[c_id], [p_id]=”79f4ce4a”)>><<IF: [c_id]=index([p_id].[related childs],1)>><<[p_id].[fld1]>>,<<[p_id].[c_enum]>>,<<EndIf>><<IF: [c_id]<>index([p_id].[related childs],1)>>,,<<EndIf>><<[c_id]>>,<<[p_id]>>,<<[fld1]>>,<<[test_t1_ref]>>
<<End>>

produces

TeeSee1_0-1709599902704.png

This is based on a plain parent - child tables pair. The id of the first row of the child records is identified by INDEX([p_id].[related childs], 1). Another <<IF>><<EndIf>> expression is added to output blank elements to the non first rows.

Hope this gives you some insight.

View solution in original post

7 REPLIES 7

To have an idea what you have tried and what's the goal, please take a printscreen from your template so people in here could give you suggestions, thanks.

I've tried 5 hours of things. Spent a lot of time assuming that I would be able to write this template against a slice.  That was a painful lesson.   Of late, I've given up on the idea of being able to directly test the count of child records (though I'd be happy to be proven wrong about that).  Instead, I'm currently working from the premise that if my invoice record includes a virtual field that holds the lowest [id] (int) for a child record, then I should be able to make a simple if statement.  But even that is failing me.  Could it be that templates also cannot work with virtual fields other than related record fields?  Anyhoo,  here's my current script:

<<Start: SELECT(Invoice_items[id], [related_invoice].[Include In Export] = "Yes")>>
<<IF: ([_THISROW].[id] = [_THISROW].[related_invoice].[First Item ID])>>
	<<[Related_Invoice].[InvoiceNo]>>, <<[Related_Invoice].[Member].[Name]>>,<<[Related_Invoice].[Create_Date]>>,<<[Related_Invoice].[Due_Date]>>,,,,
<<EndIf>>
<<[Product].[Category]>>,<<[Description]>>,<<[Quantity]>>,<<[Unit_Price]>>,<<[Amount]>>,<<[Amount] * 1.13>>
<<End>>

And from which table are you trigging your Bot?

A table named clubs triggers the bot. But the table being acted upon in
this step is invoice_items.

Just FYI

"parent_fld1","parent_c_enum","c_id","p_id","fld1","test_t1_ref"
<<Start: SELECT(child[c_id], [p_id]=”79f4ce4a”)>><<IF: [c_id]=index([p_id].[related childs],1)>><<[p_id].[fld1]>>,<<[p_id].[c_enum]>>,<<EndIf>><<IF: [c_id]<>index([p_id].[related childs],1)>>,,<<EndIf>><<[c_id]>>,<<[p_id]>>,<<[fld1]>>,<<[test_t1_ref]>>
<<End>>

produces

TeeSee1_0-1709599902704.png

This is based on a plain parent - child tables pair. The id of the first row of the child records is identified by INDEX([p_id].[related childs], 1). Another <<IF>><<EndIf>> expression is added to output blank elements to the non first rows.

Hope this gives you some insight.

This looks very promising.  Trying to test it now, but seems like there are some outages at appsheet right now.  Can't seem to test bots right now.  

Bingo!  Thanks very much.  This works great.

Top Labels in this Space