How to create a Counter IS

Hi all,

How to create a counter in IS. For example I would like to create a 9(5) counter. When ever one of my service invoked the value of the counter should be increased by one and once it reaches 99999 then it should start from 1 again. May be sound silly but I dont know how to do this.


Using the repository as a storage location (see Ray Moser’s article: you should be able to write a FLOW service that does what you need. The service might be:


The steps would be something like:

  1. Open a store. The store name could be anything you want but perhaps “MiscCounters” would work.

  2. Get the counter from the store. The name of the store variable is passed in the “counterName” parameter to your service. Save this value in a temp var.

  3. Increment the counter. If the counter exceeds max value, wrap back to 0. Put it and unlock it.

  4. Format the saved temp var to the width of maxValue and return it as counter.

  5. Close the store.

That should do it.

If you’re really only looking for a unique number, there is another way to do that. Let us know if that’s what you actually need.

Thanks Rob,

It worked, BTW I wrote a small Java service which does the same function.

Integer integer = new Integer(0);

myCounter = ++ myCounter <= 99999 ? myCounter:10000;

IDataHashCursor pipelineCursor = pipeline.getHashCursor();
Integer yourCounter = new Integer(myCounter);
String result = (String) yourCounter.toString();
pipelineCursor.insertAfter(“yourCounter”, result);
catch(Exception e)
throw new ServiceException(“Exception” + e.getMessage());

Your output variable is ‘yourCounter’, in the shared area define 'static int myCounter=10000.


Hi, MS.

What happens if the server goes down…? You’ll start your count over, right? Does that fit your business process/requirements?

Ray’s Repo solution avoids that scenario. The article is detailed and will do a good job of showing you how it’s done.


I agree with you. I wrote this piece of code before I came to know about this solution. I am using Ray’s repo solution.


I am just starting to learn WM Developer and flow services so please bare with me. I too need to create a counter for the number of times a task is created within my process. I understand that I have to open a store first before I can put something in it. Does have to happen everytime I run the service or is this a one time thing that just creates the store? Right now this is all I have in my flow service: