3

I have a sharepoint list and I want to set some value inside it. The multi-choice field is already defined and it is already pointing on data. I just want to pick one of the choices and set it in the field. I don't want to create new values and adding them inside.

    $weburl = "http://sdfsdfsdf"
    $web = Get-SPWeb $webUrl
    $list=$web.GetList("/Lists/ListName")

    $choice = # what do i have to put here ?

    $newItem = $list.AddItem()
    $newItem["multiChoiceField"] = $choice
    $newItem.update()
1
  • have you had any luck on this, currently trying to figure out the same Commented Mar 19, 2015 at 18:27

3 Answers 3

2

from msdn:

$choicevalues = New-Object Microsoft.SharePoint.SPFieldMultiChoiceValue;
$choicevalues.Add("Green");            
$choicevalues.Add("Blue");            
$i["multiplechoicefield"] = $l.Fields["multiplechoicefield"].ParseAndSetValue($i,$choicevalues);            
$i["multiplechoicefield"].ToString();            
$i["multiplechoicefield"] = $choicevalues;            
$i.Update();            
#-or-            
$l.Fields["multiplechoicefield"].ParseAndSetValue($i,$choicevalues);            
$i.Update();
1
  • 1
    Thank you for your answer. I already have seen this piece of code and it didn't fixed my problem. Plus, as I said I don't want to create new values because they already exist. Commented Feb 26, 2015 at 16:30
0

May have stumbled upon it, in Powershell, I have an actual array variable of values

$languages = Eng,Fr,Sp

I set my field to equal this array:

$NewItem["TestLanguages"] = $languages

Spent forever trying to do what was listed above as well, but this is working for me (and so simple too)

0

This worked just fine for me in SP2016 (the field already had some values selected and they were overwritten):

$valuesArr = New-Object Microsoft.SharePoint.SPFieldMultiChoiceValue; 
$valuesArr.Add("Choice Value 1");
$valuesArr.Add("Choice Value 3");
$item["SomeSPInternalFieldName"] = $valuesArr;
$item.SystemUpdate($false)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.