4

I have a field which uses the calculated column type to reference the ID field. It basically does: Name&ID. E.g. Name01, Name02, Name03 etc.

However when I add new rows to the sharepoint, this column doesn't update automatically and I have to manually click in the field to update it.

Is there a way around this? Thanks

Vin
  • 241
  • 2
  • 5
  • 6

2 Answers2

1

I've seen this behavior as well, and it's not obvious because when you first create the column (and every time you edit the column) everything looks fine and dandy.

I've found that I can get around this problem using a SharePoint Designer workflow. The workflow updates an ordinary text field to store the ID value, and then calculated columns can reference that text field instead of the actual ID field.

The steps:

  1. Add a text field to my list called ItemID
  2. In SharePoint Designer, add a new workflow to the list and set it to trigger whenever items are added or updated.
  3. Add a workflow action to store the item's ID into a string (Build Dynamic String)
  4. Add a workflow action to set the ItemID field to the value I saved in the previous step (Set Field in Current Item)
  5. Add a workflow action to update the current item (Update List Item)

Then I just have to reference [ItemID] in my calculated columns instead of [ID] and it works like a charm.

One downside is that the users end up seeing the ItemID field on the New and Edit forms unless you do something to hide it.

If you've got more time on your hands and want to avoid spamming the workflow history list, you can perform this same workaround in an event handler.

Andy
  • 21
  • 1
0

This is by design.

Calculated columns can not contain the ID field in their expression. The reason for this is that sharepoint stores the results value of the calculated field upon creation/update. Once the item is created the ID doesn't exist yet. Therefore it has nothing to populate against. However once the value is updated, as you can see the ID is populated and now available.

brian brinley
  • 2,364
  • 1
  • 13
  • 10
  • Thanks Brian, although you're right the ID field is populated, whenever I edit another field in that row, the ID field disappears and I'm left with just the 'Name' and not the numbers from the ID. This happens every time I edit the row. – Vin Mar 16 '11 at 17:14
  • That might be due to versioning, do you have versioning enabled on this list? To resolve this in the past i've had to implement a workflow or event receiver to update the persisted value. – brian brinley Mar 16 '11 at 19:08