Solved

Computed Field in SP list

Posted on 2010-08-25
9
902 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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…
We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now