Forum Discussion

Woody's avatar
Woody
Brass Contributor
Aug 16, 2023
Solved

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...
  • SvenSieverding's avatar
    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