How can I use the last Item ID in a new form?

  • 22 September 2017
  • 11 replies
  • 19 views

Badge +7

I need to populate a field with a predefined title such as "CHG0001." The "1" being the ID for the item we are about to enter. So I believe I need to pull the ID from the newest item and add one to populate this field. 

Anyone have this before?


11 replies

Userlevel 5
Badge +14

have a look on this blog  

Badge +7

This is really good. However, these numbers aren't consecutive. 

How would I guarantee consecutive number?

Maybe, subtract 1 from the outcome? 

thoughts?

Userlevel 5
Badge +13

Hmm, what is the use case that requires this to be populated on the form? Why not just not have this field appear on the "New" form and then you can set the field with workflow, and show the field in "Edit" and "Display" modes?

Badge +7

I have thought about that. It would be easy just to build this field on create, but it's a requirement to have this show as a user is submitting the request. 

Badge +7

Hi,

Create a field name "ToQuery" with default value "X".

Use the following formula in a calculated value:

Max(Lookup("ListName","ToQuery","X","ID",TRUE)) so you will get the max ID in the list.

TRUE is used to return multiple values in an array.

Am not aware of the strongly typed values.

Userlevel 5
Badge +14

what you mean with they are not consecutive?

solution is based on by sharepoint generated item ID, which is definitely consecutive.

Userlevel 5
Badge +14

if this is the only reason, then I'd rather try to convince users/project owner that this is not the way how sharepoint works.

creating customized IDs just after an item is submitted is much simpler and straightforward solution.

Badge +7

the method you suggested causes the actual numbers to skip every other one. Because as you stated SharePoint generates the ID so with this method you create one to get the ID to the page, then you delete it. Therefore, you have a number on your page now (i.e.CHG1 ), but the one you are about to create is the next ID number (i.e. ID = 2). So when you create another request the new number generated for the page is the last ID + 1 making the new request number (i.e. CHG3). 1 and 3 are not consecutive.  

Badge +7

I will probably end up doing this, at least for now, but this is not a solution. Because it breaks the requirement.

Userlevel 5
Badge +14

the point is, if you are going to generate IDs at the timepoint when an user starts filling in a form you can never avoid either gaps or duplicates.

therefore I suggested in the other post to wait until an item is submitted and just then assign it a custom ID based on item ID.

do not even rely on looking up for max existing ID, it's not reliable either.

Badge +3

Good idea ! happy.png . Thanks.

Reply