1

How can I Enforce unique values: in powershell? Client-side as well not server-side Here is the code that I have :

$ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListInfo.Title = $ListTitle
$ListInfo.TemplateType = "100"
$myList = $web.Lists.Add($ListInfo)
$myList.Description = $ListTitle
$myList.Update()
$Fields=$myList.Fields
$ctx.Load($Fields)
$ctx.ExecuteQuery() 
$myList.Fields.AddFieldAsXml("<Field Type='Number' DisplayName='SortOrder' />",$true,[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView)

$myList.Update()
$ctx.ExecuteQuery()

just need to make it a unique field

6
  • What do you mean by "unique"?
    – Brandon C.
    Commented Jun 30, 2014 at 9:23
  • Enforcing unique values
    – bimbob
    Commented Jun 30, 2014 at 9:26
  • So you want each field to have a unique value not found anywhere else in the list?
    – Brandon C.
    Commented Jun 30, 2014 at 9:30
  • in the column, say if I was creating the column on my sharepoint I would click enforce unique values
    – bimbob
    Commented Jun 30, 2014 at 9:32
  • What my question is, is how do you want this script to run? If you force unique values, what happens if a similar value is added? What is it exactly that the script should do?
    – Brandon C.
    Commented Jun 30, 2014 at 9:41

1 Answer 1

0

http://msdn.microsoft.com/en-us/library/office/ee536168%28v=office.14%29.aspx

Here is a link that should help you better understand what you need to do. I suppose just writing

$Fields.Indexed = true;
$Fields.EnforceUniqueValues = true; 

would suffice. I haven't worked with this, but the example seems like you have to do this on a list object, not a listcollection object.

EDIT: It seems, to this day, I cannot tell the difference between Acronym's (even had to look that word up to remember it). This answer applies to SSOM and not CSOM. Please see comments for more information.

$fieldname.indexed = $true; 
$fieldname.EnforcedUniqueValues = $true
$fieldname.Update()

Thanks to bimbob for supplying the CSOM equivilant.

7
  • The link you have provided is not correct, the OP is asking about CSOM, not SSOM. Commented Jun 30, 2014 at 10:00
  • Another point, $fields is a field collection (!), you could specify EnforceUniqueValues for a field, not a field collection Commented Jun 30, 2014 at 10:03
  • I understood the link provided and for me he supplied a sufficient and correct answer. Understand that a few tweaks could be made to make it a better answer
    – bimbob
    Commented Jun 30, 2014 at 10:03
  • I would recommend to update the answer otherwise it does not seem correct Commented Jun 30, 2014 at 10:04
  • 1
    Updated. Sorry for the confusion!
    – Brandon C.
    Commented Jun 30, 2014 at 10:15

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.