Solved

Computed Field in SP list

Posted on 2010-08-25
9
940 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 7

Accepted Solution

by:
arduk earned 250 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 250 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

If you create your solutions on SharePoint sooner or later you will come upon a request to set  permissions of the item depending on some of the item's meta-data - the author, people assigned as approvers, divisions, categories etc. The most natu…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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