In a State Machine, in the middle of a loop, can I process one element from the Get Transaction Data in the Process Transaction state?

Hi,

I’m trying to figure out how to properly use the State Machine workflows in Studio.

My scenario is: I have to loop over a database set of results, then do some calculations with the data I got to prepare my proper data structure I’ll later use to, finally, process it and, let’s set, generater a series of .xlsx documents with certain data on them.

I got some State Machine template with this 5 basic states:

Start → Inicialization → Get Transaction Data → Process Transaction → End process

There’s a loop between “Get Transaction Data” and → “Process Transaction”, so, to my understanding, that implies that, it’s not that the data structure (a collection, a dictionary, etc.) should be completely be filled with data and then, when let’s say, it’s full with 50 or 100 elements, send it to the “Process Transaction” state to iterate over all the elements of the collection but do it one by one, one after another. I mean, what I understand the probgram should be here is:

  • You start iterating over the rows resulting from the database query.
  • You prepare your set of data elements from that query and from other data you may need (current datetime, number of files in a certain folder, and the like).
  • After one item of “information” is ready, it will be passed to the “Process Transaction” state and do his things (generate an Excel file with the data).
  • Then go to the next database row and continue doing the same until the end.

Even if the State Machine diagram looks like this:

Am I right in my suppositions? How I’m supposed to accomplish tat? I get lost with the IN, the OUT, the IN/OUT variables and arguments through the example diagram and the scope of them.

@pere

I believe you need to change the transactionitem to datarow thats it

and in get transaction data assign each row instead of get transaction item

cheers

I’m replying to this because the robot is asking me to choose the right answer.

The one above is not a right one; in fact, for me it was barely understandable. Very lack of detail, just very two general phrases withouth almost relation to the my original question. A generic one, probably only for the sake of getting some “reward” or whatever.

I already sorted this out on my own, and the answer has nothing to do with that barely understandable “suggestion”.

My transaction item was never a datarow, and it still isn’t. It’s a dictionary of dictionaries, as stated before. And that’s what gets processed in my process transaction. And item of a collection of collections. Period.

What I ended up doing is:

  • Get a row from a database query. That’s a datarow.
  • I treat the data there the way I need and add it to me collection, adding some other data from other sources.
  • The “state change” trigger is triggered when that data element is triggered; then the machine jumps to the “process transaction”, generating my Excel file from that set of data. No sense filling an structure with 50 or 100 elements, then iterating over them in the “process transaction” state, as that’s what the state machine is for: to process A transaction, not a collection of transaction.
  • Back to “get transaction data” to prepare the next set of data, and so on.

The only “tricky” part for me is that iterating over the set of database records has to be done “manually” in the “get transaction data”; you can’t use a for each, while, do… loop to iterate over the DataTable rows as it won’t trigger the state change. As in the example in the template, you just keep the DataTable, you move through the rows by manually increasing the index before coming back each time to the “get transaction data” state.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.