Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.)

share|improve this question

4 Answers 4

up vote 0 down vote accepted

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.

share|improve this answer

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.)

share|improve this answer
    
=[ID] works when you set it up, but as soon as you create new items it'll break. –  Christophe Nov 10 '11 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. –  Anderson Karu Nov 10 '11 at 8:59
    
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. –  PirateEric Nov 10 '11 at 18:26

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.

share|improve this answer

The Solution (I found by http://www.spankh.com/archives/121):

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…

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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