Skip to main content

I'm developing a process that starts when a new item is added to a SharePoint list. As part of the process, I generate an ID for the item. Part of the ID is a number that should be incremented one at a time. For example, the first item to be added would be 1, the second added would be 2, etc. As part of this, I need to know how many items are in the list. Is there a way to get the list's item count?

The way I was able to display the next ID was to create a parameter that would hold the current (list) value, mine was "traverequestnumber".  You would then create a rule to execute a Get List method against the SharePoint list.  The Output Mapping would be ID into the "travelrequestnumber" field.  then the secret sauce is the sort...you have to then sort by column ID Descending.  That will get you the last value item in the list.  If you want to display it to a user with the next ID available, you'd have to create an expression with travelrequestnumber+ 1 and put that into a data label.


I've been thinking about a process that locks next ID in a sharepoint or sql table, by firing an "insert" method prior to the user updating their data then "updating" method their information...but I haven't gotten around to it.



I had the same requirement, however I am not allowed to do any custom code on this SP farm at all, so the best I could do is use K2 Studio.

I worked on this thing all day, couldn't find anything anywhere (here, in the K2 help, or even with my 20,000 coworker consultants), so I just sat and hacked.

Here's what I came up with.

1) Create a Sharepoint Search event, search for every item in the list with an ID greater than 0. Dump it all in a content field named listCount.

2) Then you can get the count from the inline function: Count(listCount_@ID) 

 

The inline function is under the

List > Count

in the Objecct Browser.  This will open a function window, and in the box for the Values input the field from the object browser at:

XML Fields > gname of your Process] > listCount > Items > Item > ID

 

This returns a List of all the Items, which the Count() inline function can use as the input values.

 

This might not make a lot of sense explained like this, but if you're willing to poke areound at it and test it out, I'm sure you'll get it working.

 


Reply