代码改变世界

SharePoint 2007 如果在计算列中使用Today变量

2012-06-12 10:57  努力学习的小熊  阅读(1480)  评论(1编辑  收藏  举报

          默认情况下在SharePoint计算列的公式中是没办法使用Today这个变量的。如果使用,在保存的时候我们会得到这个错误信息。

         Calculated columns cannot contain volatile functions like Today and Me.

         

         这就没办法使用了么?当然不能,我们可以骗过系统使这个Today变量变得可用。

         方法就是创建个名为Today的Column。 然后编辑公式,使得公式保存不会出现这个提示错误。但是这时公式的计算结果还是根据这个Today的Column的值来计算的。最后一步,删除掉这个Today Column,这时你会发现计算结果发生了变化,已经按照当天时间的值来进行计算了。

         验证一下:

         1 Create Today Column. Column type is "Date and Time".

         2 Creast DateDiff Column. Column type is Calculated. Formula =[Due Date]-Today

         

         3 Save it. We can see the result.

         

         4 Delete the Today column. We can see the value of DateDiff is changed.