Solved

Computed Field in SP list

Posted on 2010-08-25
9
919 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
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 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
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…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

930 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

16 Experts available now in Live!

Get 1:1 Help Now