I have built an expression rule where I am using a!foreach() and looping through items. Below is the query.
a!localVariables( local!var: a!queryRecordType( recordType: 'recordType!rec_type1, pagingInfo: a!pagingInfo(1, 10) ), a!forEach( items: { local!var}.data, //4 data items from the record type table are that it can iterate on// expression: fv!item['recordType!rectype1.fields.col1'] [1] ))
The record type I am querying here has 4 items that I am iterating in using a!foreach(). Now expression gives a single output (specific cell's data from table i.e. first record's col1 value). My expectation was that this would give same table cell data as output but 4 times instead of 1 time. Is it due to the fact that in every iteration fv!item moves to the subsequent item as current array item and therefore cannot give that cell's data as output remaining 3 times since it has already moved ahead to next item.Let me know if I am thinking correctly or is there some other reason. (Refer: Below image shows the single output for above query.)
Discussion posts and replies are publicly visible
May I know why you specified [1] in the end of expression, once try without specifying any index
Nothing specific, just trying to play with expression and loops. So based on question above, let me know if what I have mentioned is correct regarding how this loop is working in this scenario or some other reason is there.Without specifying any index, I know it gives the list of col1 items from all rows/records. Like if Age is the column, then it would give all 4 Age items from the record type/table.
a!localVariables( local!var: a!queryRecordType( recordType: 'recordType!rec_type1, pagingInfo: a!pagingInfo(1, 10) ), a!forEach( items: local!var.data, /* Remove the curly brackets */ expression: fv!item['recordType!rectype1.fields.col1'] /* The angular brackets are not needed */ ) )
Thanks Stefan, I have 2 questions 1- what is the difference between {var}.data and var.data, what is the impact in both cases?2- How does fv!item works in both cases, is there a difference in the way it hold current array items in both cases?
1) There are edge cases where putting a list into a list, just results in a list with one item that is that list. In other cases, Appian merges the items into just a flat list. While typically not a problem, this can lead to painful bugs almost impossible to debug.
The result is a list of variant that contains another list that has 10 items. Now the foreach iterates on only a single item. Your way of indexing returns the first item in the list only.
Fixed:
2) fv!item is always the iteration's item. It is just a matter of what are the items in that list.
ayushsrivastava said:Without specifying any index, I know it gives the list of col1 items from all rows/records
I'm afraid you are fundamentally misunderstanding what "fv!item" does.
Hi Mike,I was considering it to work like this --> If I give "var.data" for items where var.data is a list of items (row of records) from a record type, then for every iteration, fv!item would hold the current array item i.e. in first iteration it would hold 1st row of record, in next iteration it would be 2nd row of record and so on.Let me know if this is correct else it would help if you could provide a small example to explain working of fv!item. thanks.
This is correct. In your specific example from above, you broke that because you wrapped "var" into a list first.
This is why I said above: "fv!item is always the iteration's item. It is just a matter of what are the items in that list."
ayushsrivastava said:Let me know if this is correct else it would help if you could provide a small example to explain working of fv!item.
What you wrote here sounds basically correct, but I was worried because in this respect the syntax you wrote in your original example, specifically appending it with "[1]", makes no sense.
Yeah, actually I had realized that looking at the outputs, then your answer confirmed it. Since initially I don't know why I thought that it would work only if I wrap it and then put .data, but thanks Stefan for helping me out.Guess I was thinking correctly but applying it incorrectly.
Hi Stefan,Can you check and help me understand that why in below case we see "list of variant" instead of "List of GL report items" directly? Since if I had just queried GL report below then it would have given me a list of map or for data only it would have said "List of TA GL Report - n items". (Not sure if it is due to the filter condition which is using another record type.)