11

I have a calculated field in a SharePoint 2007 list. I want this calculated field to include the ID of the item but I could not find the ID column inside the "Insert Column" List box.

How should I go about in order to get my calculated field to have the ID of this item. (For your info: the calculated field does not only just contain the ID of this item.)

1

5 Answers 5

6

If you need to use the ID in a calculation, the best approach is to do the calculation in a workflow and set a column to the value returned by the calculation.

IDs can work in calculated columns, they are unreliable, speaking from experience. Now I always use On creation and on change workflows in situations where I absolutely have to use the ID value in some sort of calculated column.

1
  • 2
    just recently did this. wanted an ID different and more unique than the built in id. did a quick flow - on item created - create ID - done. works great, thanks for the ideas
    – Brian
    Commented Nov 1, 2018 at 19:34
3

Thanks everyone for your help but I have do some testing and notice that I can simply use =[ID] to retrieve the ID even though the ID is not listed inside the "Insert Column" list box.

Kind of quite surprise for me as I thought that the ID field will be display in the "Insert Column" rather than hidden.

(Do let me know if it does not work in your case.)

3
  • 7
    =[ID] works when you set it up, but as soon as you create new items it'll break.
    – Christophe
    Commented Nov 10, 2011 at 5:33
  • Yeah. That's bad. When I create a new items, every things break. (Wonder if this is a bug or not). Thanks Christophe for the enlightenment. Commented Nov 10, 2011 at 8:59
  • 1
    It isn't intended to be used in calculated columns. you can add it, but as I mentioned, the functionality of it is buggy. Using a workflow to set a column value to the ID to use in your calculated filed or building the calculated field directly in a workflow are your best, no code options. Commented Nov 10, 2011 at 18:26
2

Unfortunately I don't think you can include ID as part of a calculated column. It's been a while since I looked at this but from memory I think it has to do with the ID column having a null value until the item is saved for the first time, so SharePoint doesn't allow it.

A workaround that I've used in the past is to implement an event handler on the list which will update a custom integer column on the list with the item id after the ItemAdded event has occurred. Your calculated column can then use this custom column as part of its calculation.

-1

You could also do a calculated column with the following formula.This takes the value of the ID column and adds it to your specified ID value.

="PROJ_ID_"&ID

Based on the row's ID number the result would be, for example the 8th row: PROJ_ID_8

1
  • 3
    As mentioned back in 2011, this only works on creation. Upon edits, the ID part of the calculation becomes an empty string. Commented Oct 20, 2015 at 12:41
-1

The Solution (I found by www.spankh.com/archives/121 (link now broken)):

The solution is to run the workflow twice on each item. Once to set the numeric SharePoint ID field, and once to use the numeric ID calculated column. let’s see the whole thing in action:

Create two custom lists:

  1. ID generator – This is a list that will be used to generate the title for our main list:

Title SPID: Numeric SPID00000: Calculated, Single line of text, =TEXT(SPID,"00000") DateCalc: Calculated, Single line of text, =TEXT(Created,"YYMMDD") 2. Main List – This is our list that we want to set the title to YYYYMMDD-00000. (we only need a title field for this example):

Title Create the workflow for the ID Generator list: Workflow Step 1:

{Set Field in Current Item} Set SPIDNumeric to ID. {Build Dynamic String} Store [CreatedYYYYMMDD]-[SPID00000] in Variable:NewTitle. {Set Field in Current Item} Set Title to NewTitle. Create the workflow for the main list: Workflow Step 1:

{Create List Item} Create item in [ID Generator List], Set Title to "Title" (Output to Variable: create) {Pause for Duration} Pause for 0 days, 0 hours, 0 minutes. {Update List Item} Set Title to "Title". {in the Find the list item section: Field: [ID Generator List]:ID Value: Variable: create} {Set Field in Current Item} Set Title to [fx]: Source: [ID Generator List], Field: [Title], {in the Find the list item section: Field: [ID Generator List]:ID Value: Variable: create}. Viola! We have it! Create a few items in the main list and watch as they all update themselves to the ID number we wanted…

1
  • The link in this post is no longer valid and brings you to a redirecting page. Please remove it as soon as possible. Commented Feb 3, 2016 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.