You are viewing limited content. For full access, please sign in.

Question

Question

Which way to have a global counter?

asked on April 30, 2015

Hello!

 

Anyone have a favorite way to have a global counter?

 

I'm thinking of a workflow where each incoming request is assigned the next in a sequence of sequential numbers.

 

For some reason I thought I saw some sort of global counter somewhere in the interface, but I can't find it now.

 

My current theory is to have a document somewhere in the repo with security so it is only visible by the workflow, and for it to have a field with the current counter value.  Then set up a part of the WF to -

  • Find entry by ID (to get my counter document)
  • retrieve field value (to get the value from that field.)
  • Token calculator to +1 (Add 1)
  • Assign Field Value.  (write the new value back to the doc field.)

 

I'm sure there are bugs to work out, but I think that should work.

 

Any thoughts?

0 0

Replies

replied on April 30, 2015

Michael - Here is a link to a post that uses a similar approach;

 

https://answers.laserfiche.com/questions/59173/how-can-I-generate-an-incremented-Id-number-with-workflow-

 

Another way, although more complex, would be to work directly in SQL.  Adding a table/field/stored procedure to a SQL database.  The stored procedure would increment the counter and return the id.  You could use the Workflow Query activity to retrieve the results of the stored procedure.

0 0
replied on April 30, 2015

A workflow will not work for generating unique numbers because Workflow is multi-threaded, so multiple instance could run at the same time. Reading a value from a SQL table, incrementing it and writing it back won't work for the same reason (you can have multiple instances reading at the same time).

You could do it by using a SQL sequence if you have SQL 2012 or higher.

0 0
replied on April 30, 2015 Show version history

In SQL versions prior to 2012 you can create a table with an IDENTITY field and SQL will generate non-repeating sequential numbers that can be used as unique identifiers, regardless if the requests are multi-threaded or not.  With SQL 2012 MS introduced a 'feature' where IDENTITY field values were still unique but could have gaps in the sequence (depending on the IDENTITY field type and under specific circumstances).  For SQL 2012 and later the recommendation is to either use a 2012 SEQUENCE or modify the SQL startup parameters to revert to the earlier behavior.
 

0 0
replied on April 30, 2015

What problem are you trying to solve with your global counter?  As Miruna notes, your suggested implementation has a race condition that would require locking to solve.  SQL sequences have cases where they might skip numbers, is that a problem?  Probably the easiest solution is to use guids, which don't require any kind of coordination to generate.  Can you use that data type?

0 0
replied on May 1, 2015

We are moving a manual process into a workflow.  

The current process uses a log book where staff look up and assign a unique number.

This number is used to reference that "case" outside of the system, and even outside of the organization.  "Call up XXX and tell them we need an update on Case YYYY"

The staff just wanted to have the scan op have a log book to look up and assign the numbers as new projects are created, but this seems so.... 80's.  : )

GUIDs would serve the same purpose, except that they aren't especially human-readable.

 

If only we could lock a document...

Hmm...  What about a "Simple Synchronization Sequence?" I've never used that action before, but could you use one with the same sync id to read and write to a counter doc?  As I read it, if I wrap the "read value/calculate token/write value" section inside a Sync Sequence, then they shouldn't step on the other toes, right?

0 0
replied on May 1, 2015

The simple synchronization sequence is for temporary locks on Laserfiche documents.

Is SQL 2012 really not an option for you?

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.