?
Solved

Computed Field in SP list

Posted on 2010-08-25
9
Medium Priority
?
987 Views
Last Modified: 2012-05-10
I have need to do the exact thing described on the following page in one of our doc libraries - except I can't figure out how to add the Computed Field that is described.  Can somebody help me step by step ... would greatly appreciate it.

http://stefan-stanev-sharepoint-blog.blogspot.com/2010/05/how-to-display-all-versions-in.html 
0
Comment
Question by:sandipkharde
  • 5
  • 4
9 Comments
 
LVL 7

Expert Comment

by:arduk
ID: 33527030
You could add the computed field using powershell

The link below describes how to do this. Adding at the site collection level will mean that you can then include the column in any of the document libraries in your site collection:
http://get-spscripts.com/2010/06/create-new-site-column.html 

shouldn't be too difficult to change this script to add a column at doc lib level if you preferred - I think you would just have to change the line
$web.Fields.AddFieldAsXml($fieldXML)
to be:
$docLib.Fields.AddFieldAsXml($fieldXML)
Where $docLib is a reference to your document library.

Hope this helps!
0
 
LVL 7

Expert Comment

by:arduk
ID: 33527038
sorry, forgot to add, the $fieldXML value should be set to the schema xml of the computed field in the link you have provided (I would probably generate a new guid for the ID field as well)
0
 
LVL 8

Author Comment

by:sandipkharde
ID: 33528134
I am using MOSS 2007 not SharePoint 2010, could you pelase tell for sharepoint 2007.Thanks.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Accepted Solution

by:
arduk earned 1000 total points
ID: 33528355
the attached code is a powershell script that will create the field.

After running the code in powershell, you can edit a view, and include this column in the view.

You will need to update the code with your values for site collection URL, site name and list name.

Hope this helps.
[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") 

# get the site collection 
$site = new-object Microsoft.SharePoint.SPSite("http://YOURSITECOLLECTION") 

# get the web site
$web = $site.OpenWeb("YOURWEBNAME") 

# get the list in the web site and create the new field
$documentLibrary = $web.Lists["Your List Name"]
$fieldXML = "<Field ID=`"{ccccdddd-3710-4374-b433-61cb4a686c12}`" ReadOnly=`"TRUE`" Type=`"Computed`" Name=`"VersionLinkFilename`" DisplayName=`"Version link`" DisplayNameSrcField=`"FileLeafRef`" Filterable=`"FALSE`" AuthoringInfo=`"(linked to version)`" SourceID=`"http://schemas.microsoft.com/sharepoint/v3`" StaticName=`"VersionLinkFilename`" FromBaseType=`"TRUE`"><FieldRefs><FieldRef Name=`"FileLeafRef`" /><FieldRef Name=`"FileRef`" /><FieldRef Name=`"_UIVersion`" /></FieldRefs><DisplayPattern><HTML><![CDATA[<a href=`']]></HTML><HttpVDir CurrentWeb=`"TRUE`" ></HttpVDir><HTML><![CDATA[/_layouts/versionredir.aspx?FileRef=%2f]]></HTML><LookupColumn Name=`"FileRef`" URLEncode=`"TRUE`" /><HTML><![CDATA[&Version=]]></HTML><Column Name=`"_UIVersion`" /><HTML><![CDATA[`'>]]></HTML><LookupColumn Name=`"FileLeafRef`" /><HTML><![CDATA[</a>]]></HTML></DisplayPattern></Field>"
$documentLibrary.Fields.AddFieldAsXml($fieldXML)

# clean up...
$web.Dispose()
$site.Dispose()

Open in new window

0
 
LVL 8

Author Comment

by:sandipkharde
ID: 33536132
Thanks for your prompt reply..

I am aware of stsdm command I never used pawershell ...even I don't know how to execute it.

is there any other way please?
0
 
LVL 8

Author Comment

by:sandipkharde
ID: 33550210
Hi Arduk,
your code seems use ful for me.
could you please help me how can use the powershell code...how can I execute..pls help me out.
thanks in advance.
0
 
LVL 7

Assisted Solution

by:arduk
arduk earned 1000 total points
ID: 33555037
I strongly recommend that you try this out in a dev environment first:
- goto your Sharepoitn server
- create a file called createfield.ps1 and save it to (for example) c:\powershellscripts
- edit the file, and paste in the code above. Make sure you update the url of your site collection, the web site name (empty string if it is the root of the site collection), and list name
- save the file
- on your Sharepoint server go to Start->all Programs->accessories->windows powershell
- right click Windows powershell and choose "run as administrator"
- change to the directory that you saved the file to (eg cd powershellscripts)
- if you haven't used powershell before, you may need  to change the execution policy using the following command:
set-executionpolicy unrestricted
NOTE: setting to unrestricted has security implications that you should ensure you are comfortable with - you will need to research this yourself in order to make sure you are happy with this, and that it meets your company's security expectations and guidelines. I do not recommend unrestricted, but am giving you this information to ensure that this script will work.
- type .\createfield.ps1 and press enter to run the script

hope this helps
0
 
LVL 8

Author Comment

by:sandipkharde
ID: 33560802
Thanks a lot...Your rock !!!
0
 
LVL 8

Author Closing Comment

by:sandipkharde
ID: 33560812
.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For SharePoint sites, particularly public-facing ones, there are times when adding JavaScript, Meta Tags, CSS Styles or other content to the page <head> section is more practical than modifying master pages.  For instance, you could add the jQuery l…
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question