views:

496

answers:

2

I have a SharePoint list with a column that was originally defined as date/time and has been manually populated with date/time information. I'd really like to populate this column automatically based on the status of another field changing (e.g. =IF([theStatus]="Closed",[Modified]).

When I edit this date field that I'd like to add the above code, I paste the script into the "Calculated" field and when saving, I get the following error:

The formula contains reference(s) to field(s).

Would be greatful to know if I'm doing something wrong or SharePoint just doesn't allow this type of modification.

Thank you.

+2  A: 

In the case of a DateTime field, the "calculated" default value is primarily for things like =Today+1. You cannot reference other fields, unfortunately, really the only thing you can reference as a variable is Today. In order to reference a field in a calculation, you would need to use a Calculated field type configured to display a DateTime, instead of a DateTime field type. Unfortunately you cannot convert an existing DateTime field into a Calculated field, so you would have to create a new field.

If you wanted to play in the object model, though, you could always use a workflow or event handler. I think a SharePoint Designer workflow could also do the trick, if you went that route.

ccomet
Your comment is correct for the 'default' value but thats not what the OP is after (or at least that's how I read his question).
Ryan
@Ryan The default value is only addressed in the first 2 sentences. I read his question the same as you did, but I'm suggesting a method that is an alternative to a workflow or event handler, which is a Calculated field type.
ccomet
+1  A: 

Actually, I did something like this. From an user entered date and time, I had to build a user define code, something like "2009/12/13 07:05-AVALTG23" for example.

I did not come with any other way:

  • Creating a custom action (in VS2005) that, given a date time, returned a string in the format and with the operations I wanted. Since you are programming your custom action and returning a string, you can pretty much do whatever you want.
  • When an object was create, a Workflow starts, which populates my "Custom Code" field.

So, for anything so simple as getting a column value, formatting it and populting another, I had to develop a custom activity and create a workflow.... Lots of work, but pretty much the only way I could find.

Hope this helps!

Daniel Dolz