How to Loop Through Records in a Process in Creatio (formerly bpm’online)

Awhile back I wrote an article about how to notify activity participants with a looping process but I thought that it would be a good idea to make the loop process it’s own topic. In that article, the process looped through the activity participants In this article, I will simplify that and just show how the looping part works.

The steps for looping in a process are pretty simple:

  1. Set a condition on the records you want to process. Usually this is done by adding a field on the object so you can mark or flag the records you want to process by setting a value on that field.
  2. Read the records with the flag field set that you did in step number 1. The read data will give you the first records with the flag set.
  3. Do whatever you need to do in the process using the record you read in step number 2.
  4.  Clear the flag field on the record.
  5. Go back to the read element in step number 2. This time since you cleared the flag on the first record you’re going to get the next one. You’ll continue this until there are no more records to read.

Here’s what that looks like in it’s simplest form.

In this process I start out with a modify data to set a flag on all the records I need to use. This is where you set the conditions of which records you want to work with. You just add these conditions as filter conditions to the modify data so you only set the flag field for the records that match the conditions. The modify data field only edits one field which is our flag field. You’re basically just marking the records you want to work with. Then I will go on to read all of the records that are marked using a read data task. The only filter for the read data is records that have my flag field set. The read data task will give me only one of those records at a time, which is the first one. The next thing in the process above is the yellow diamond and that is called Exclusive OR Gateway. It lets you make a decision and go one way or the other. What it’s deciding is if we got a record from our read data or not. Maybe we didn’t get a record that was flagged or we just looped through them all if so it would end and go to the terminate. The way you check if it got a record or not is by checking the Id of the record and seeing if it equals Guid.Empty. The formula you’ll add to the Exclusive OR Gateway to make sure you got a record would look like this:

[#Read flagged records.First item of resulting collection.Id#] != Guid.Empty

If the Id does not equal Guid.Empty that means you got a record, so this is the condition you add to your Exclusive OR Gateway – if Id != Guid.Empty you continue, otherwise you go to the terminate. If it did read a record it will continue down to the script task. The script task in this process just represents where you would put the actual tasks that you want to do to the records you’re looping through. This could be one task or a whole lot of things. When you’re done doing the things in your process, you clear the flag with a modify data so the next time you read the flagged records the one you just modified won’t show up. The process will repeat this until you have no more flagged records.

The only other thing to consider is how many times you might loop. The process has a setting that sets how many times you can loop, it defaults to 100 so you might have to increase it if you are going to loop more than 100 times.

That setting is called Maximum Number of Repetitions, be sure to set that higher than the number of times you are going to loop.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!