Forum Discussion
Woody
Aug 16, 2023Brass Contributor
PnP - Add choice value in specific position
Hi! With the following code I am able to add a new value to a choice column in SharePoint Online. The new value is always added at the end of the list of values. The challenge is how to add a...
- Aug 17, 2023
Hi Woody
"$ChoiceField.Choices" is an array and you add "Dropped" at the end of that array with the line$ChoiceField.Choices += "Dropped"
To insert a value at another position in the array use this code$newValue="MyNewValue" $insertAtPosition=2 $ChoiceField.Choices=$ChoiceField.Choices[0..($insertAtPosition-1)]+ $newValue + $ChoiceField.Choices[$insertAtPosition..($ChoiceField.Choices.Length-1)]
Best Regards,
Sven
SvenSieverding
Aug 17, 2023Bronze Contributor
Hi Woody
"$ChoiceField.Choices" is an array and you add "Dropped" at the end of that array with the line
$ChoiceField.Choices += "Dropped"
To insert a value at another position in the array use this code
$newValue="MyNewValue"
$insertAtPosition=2
$ChoiceField.Choices=$ChoiceField.Choices[0..($insertAtPosition-1)]+ $newValue + $ChoiceField.Choices[$insertAtPosition..($ChoiceField.Choices.Length-1)]
Best Regards,
Sven
- WoodyAug 17, 2023Brass Contributor