State Machine for each loop

Hi, I have a query that in one file i have made a process of login in login file each user id and password is read from excel and then go to next process and then next user is login. But in login file i use for each but it first login all the users and then go to next process.

if i invoke all files in one process then it working fine and first user process is complete then after login the next user

but by using state machine it first login all users and then go to the next process.
So please guide what should i do

Hi @praveen5 ,
I see your requirements, I think state machine is not good with it, why you select it in here?
If you use it, I think you can use a loop each row in your file and a state inside it


hope it help you,

so then in List of Items what should i write

you have a 1 excel file have infor to login, that’s right?
you need read it first to get data table
for each row in data table, and state have step-by-step inside that loop

But if i use state in for each row in data table than it goes to login state where it reads the excel and for each loop to enter the logins details then it sends same error that first it will login all users and than go to next state but i want to complete process of first user and then login the next user details



gst3

As im using state under loop but then it goes to login state and there is for each to write the login details But it read all the users and not complete the process of first users.

Hi,

I think I have a similar problem.

I want to automate the creation of a bunch (hundreds) of documents, comprised of data I get via database query, then do some checks in certain disk folders, gather some extra related info, then create and write each document.

According to the General Bussiness Process diagram from the Robotic Enterprise Framework ( Studio - Robotic Enterprise Framework (uipath.com))

I should be able to do something like:

  • Get transaction data: retrieve the information from the database. Get ONE row from the database, then do the extra information gathering process in the folder that belongs to that database row info. Now I have the required “Transaction Data” info, then pass it to the “Process transaction” block.

  • Process transaction: create my document, success.

  • Then go back to the Get Transaction Data state and jump to the next item in the database dataset (or “next row”), gather and prepare all the info for the next transaction, continue in a loop until I finish with all the data.

What I don’t want to do is:

  • Prepare all the collected data and fill it in a huge data structure like a big collection in the “Get Transaction Data” state.

  • Send this big amount of data (I don’t know if Studio does it by value or by reference, by the way), then send it to the Process Transaction state, then loop again in this big collection, create all the documents in a loop.

That way there’s a chance I would run out memory easily, as there’s a lot of elements a a lot of info to gather. I hate this inefficiency, plus it would be trice ineficcient: first, one loop to read get all the values from the database, then another one to create and fill the new data structure members for each document, finally read everything in a third loop to finally create every document.

Based on the complexity of the Robotic Enterprise Framework, its use of in and out variables and the direction of the arrows between Get Transaction Data and Process Transaction, it suggests to me that this could be accomplished in the way I dreamed, but I’ve tried my best to reproduce this logic with actual real operations and data and I can’t find the “magic” to pass one set of data from the “Get Transaction Data” to “Process Transaction”, then go back to Get Transaction Data continuing on retrieving and preparing the next element. All I get is always sequantially ending all the tasksin Get Transaction Data, then when it’s done it jumps to Process Transaction (which, in this case, should be “Process Transactions”).

Any hints? Is this doable? Am I wrong in my assumptions?

I think this could be a new topic, since the issue seems a bit different than in the original post. But sure, it seems feasible. If you’re going to do it on top of REFramework, you will need to change some things. Maybe you can post some log messages on the errors you get? If you’re not using queues, you will need to change some things in the SetTransactionStatus workflow.

I’m not getting any error messages at all, @efelantti … it’s just that it doens’t do what I’m expecting to, but just finish the for each loop sequentally inside every state…

And sorry for stealing this thread; as I thought it seemed similar enough, maybe the OP found a solution for his problem…

The log messages might still provide information on the process flow. Or you could run it in debug mode to see what happens. If it’s possible for you to provide more light on what you have done / how it works now / how you would like it to work, we could provide better assistance.

I’ve already done that you suggest, of course. Debugging is a must. The thing is that I don’t seem to find an I/O mechanism for the variables fo from the Get Transaction Data to the Process Transaction during the same loop iteration, and I cannot find any working example of that.

Oh, sorry didn’t understand that initially from your problem description. It’s not technically feasible to create a For Each loop that would continue between the states. What you need to do, is in Get Transaction Data state get one item, which gets processed in Process state, then Get Transaction Data gets next item, it gets processed etc. until there’s no more data.

Yeah, that’s what I want to accomplish, just that every item from the Get Transaction Data comes from a For Each loop…

If the data source is a database, you could change the query to return just one item. But then you need some kind of “Status” column to determine which item gets returned.

Or you can fetch the data in Init state, create a new index variable scoped to the whole State Machine and use it in Get Transaction Data to return the item that should be processed.

Instead, in the Fetch Transaction Data what I have is an initial if, as in the Robot Framework template, which checks if we are in the 1st transaction (so it runs the query and fetch the dataset) or if we are in subsequent ones, and then fetches the current row.

To my understanding, it should be the same.

Then I assign some data of the current row plus some other info I need via the output variable of a workflow that, when it’s called, it’s assigned to a General Business Proces scope variable. Then I check, to trigger the transition change, that its value is not null. But it does nothing.

I understand is more or less the same as you suggested.

Perhaps you can post some relevant screenshots? Or send a sample xaml file?