0

I am writing a script for assigning the default value of a column in SharePoint library:

$spFieldType = [Microsoft.SharePoint.SPFieldType]::Text
$sList.Fields.Add("OpCoNam",$spFieldType,$true)
$sList.Fields["OpCoNa"].DefaultValue="$sList.Title"
$sList.Update()

But no value is getting added.

1 Answer 1

1

You should update the field as below

$spFieldType = [Microsoft.SharePoint.SPFieldType]::Text
$sList.Fields.Add("OpCoNam",$spFieldType,$true)
$sList.Update()

$f = $sList.Fields["OpCoNam"]
$f.DefaultValue = "DefaultValue"
$f.Update()
2
  • Amal: thanks it is working but the column created is a mandatory value column. Any way to make it non-mandatory?
    – Aquarius24
    Mar 20, 2015 at 14:04
  • 1
    Yes, pass $false to Add method Mar 20, 2015 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.