Reputation: 305
I have a SharePoint 2010 site and have there a column assigned to a Lookup. Can I assign a default value to the column?
Upvotes: 0
Views: 470
Reputation: 4208
We can use PowerShell script to set default value to lookup column.
$web= Get-SPWeb http://sp2010
$list = $web.Lists["CustomList"]
$listField = $list.Fields["TestLookup"]
$listField.DefaultValue = "1"
$listField.Update()
Or using Infopath to achieve it.
Article: SharePoint 2010 - Set default value for a lookup column using InfoPath and no code
If you want to set default value to lookup column in client side, we can use CSOM with PowerShell to achieve it.
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$url="http://sp2010"
$userName="administrator"
$password="**"
$domain="test"
$listName="CustomList"
$fieldName="TestLookup"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object System.Net.NetworkCredential($userName,$password,$domain)
$ctx.Credentials = $credentials
$list = $ctx.Web.Lists.GetByTitle($listName)
$field = $list.Fields.GetByTitle($fieldName)
$field.DefaultValue = "1"
$field.Update()
$ctx.ExecuteQuery()
Upvotes: 1