none
Custom Column: Retrieving ID of a list item in calculated field RRS feed

  • Question

  • Hi there

    When opening a list item in view mode the ID of the item is not displayed. Strangley the ID Column cannot be selected to be displayed. Therefore I made a calculated field with this simple formula: ColumnName = ID.

    This works fine. The problem is: When editing and saving the item the calculated field displays the value '0' instead the actual ID (which has not changed of course). This seems to be a bug of MOSS. When I change the properties of the column (for example switching the return data type from 'Number' to 'Text') the ID is displayed again correctly.

    Has anybody else experienced this problem?
    Does someone have a workaraound?

    Many thanks!
    JJ

     

    Tuesday, March 6, 2007 3:28 PM

All replies

  • nobody got an idea here?

    thanks alot!

    JJ

    Monday, March 12, 2007 1:04 PM
  • Hello:

     

    I am also experiencing a similar problem - could be a bug in MOSS 2007 (I have not tried it in version 2).  I am trying to create a caluculated column based on the another column - [Approval Status] but I am getting the following error:

     

    One or more column references are not allowed, because the columns are defined as a data type that is not supported in formulas.

     

    The [Approval Status] column shows up on the list of available columns for formula insertion.  I don't understand why the column is available on the list when I am not allowed to use it?  I understand that the [Approval Status] column is system generated when I turn on Content Approval; however, should I be using some kind of system function to access the column?  Something like GetSysColVal([Approval Status]) - just an example?  My calculated column expects a single line of text in return, and I have tried changing it to numbers but to no avail.

     

    I would greatly appreciate any pointers or insight on this.  Thanks in advance!

     

    Shola.

    Friday, March 30, 2007 2:42 PM
  • Since the Microsoft support team does not appear to be responding to your issue, I figured I would confirm that I am having this issue as well. Add it to the long list of bizzarre things that Sharepoint does (or doesn't do).
    Wednesday, April 11, 2007 5:16 PM
  • What you can do is a feature that shows(copies) the ID for al columns with a spicific name. In this example the column name is PrefixID.

     

    protected bool ValidateItem(SPItemEventProperties properties)
            {

              try{

               Item["PrefixID"] =  Item["ID"].ToString();

               }catch(){}

         }

    Thursday, May 10, 2007 11:24 AM
  • I am having the same problem with MOSS 2007 (12.0.0.6039).  

     

    I created a custom SharePoint list with a calculted field with the formula "=ID".  The list displays the correct ID values when the field is first created, but if a list item is edited the ID will then be displayed as 0.

     

    Is their a fix, other than having to create and install a feature?

     

     

     

     

     

    Monday, March 24, 2008 4:58 PM
  •  

    I got same problem!   is there any answer for it ?
    Tuesday, June 17, 2008 1:34 PM
  • I have the same problem.  Can anyone help??

    Tuesday, June 17, 2008 6:24 PM
  • You cannot reference the ID of a row for a newly inserted row. The ID does not yet exist when the calculation is performed.
    From this article

    Not sure if that explains the weird behavior, but might have to do with that..
    Monday, July 7, 2008 12:56 PM
  • Use SharePoint Designer to create a workflow to create a column based on ID.

     

    • Proposed as answer by 123GregAD Monday, August 28, 2017 11:27 PM
    Wednesday, July 9, 2008 10:55 AM
  • I'm totaly agree with andrewwiseman. The only way to use the ID in a calculated field is to use a workflow when an Item is changed or added.
    You must define a dynamic string in SPD Workflow with the ID and then Update the field in your list element.
    This is the only way. Cause the ID is not existing yet when you are in the form.


    Nicolas Georgeault Collab Solutions Consulting
    Friday, August 29, 2008 12:36 PM
  • a very obvious thing to want when doing approvals is save/fix the approval date of a document approval process - workflow or not - in a meta data column.

    lets say you create a column [Approval Date]. u might want to set that column value to Today() - which is one obvious function NOT actually available or might rely on the modified date. the date should be set as soon as [Approval Status]=Approved. having [Approval Date] column as calculated field would be nice but at same time seems resonable this change in approval status can only be caught by a workflow (apart from not having a today() function - which might be available in a workflow). a complete custom workflow - although a simple one - just seem such overkill for automatically setting a column value...

    its like using a db trigger on change of column value in db table. suppose that could easily be done if there was a moss datamodel ;)
    Tuesday, October 7, 2008 4:34 PM
  •  

    Nicolas Georgeault said:

    I'm totaly agree with andrewwiseman. The only way to use the ID in a calculated field is to use a workflow when an Item is changed or added.
    You must define a dynamic string in SPD Workflow with the ID and then Update the field in your list element.
    This is the only way. Cause the ID is not existing yet when you are in the form.


    Nicolas Georgeault Collab Solutions Consulting



    Can you explain in more detail what you would do to this:  define a dynamic string in SPD Workflow with the ID and then Update the field in your list element.



     
    Wednesday, November 5, 2008 7:48 PM
  •   Hi Larry,

    Sorry for the silence....

    About your problem.
    From SPD you had to create a new workflow on your list. Ask to the workflow to start when element is create or modified.
    Take the item value and define your operation (calculated,...) And push the operation result in a result column.

    Take care about the check INn/out if your list use it.

    You can find many blog post about this procedure. I will look after some this evening.

    See you.
    Nicolas Georgeault
    Nicolas Georgeault Collab Solutions Consulting
    Thursday, February 12, 2009 2:20 PM