Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

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

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…

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top