1

I have tried following script to set default value of Yes/No Field to Yes which is by default set to No in list Yes/No column, i get false result at last line.

I have tried these values: 1 , $true, "1", Yes and "Yes" at line 1, but nothing works

 $item.Fields["My YesNo Field"].DefaultValue = "Yes" //Line 1
    $item.Fields["My YesNo Field"].Update()
    Write-host $item["My YesNo Field"].ToString()

Any idea to fix?

  • 1
    Changing the default value of the field should be at the list setting not the item. Set the default value on the list, then try to update the list item value $item["My YesNo Field"] = "Yes" – Eric Alexander Mar 10 '15 at 15:12
2

Changing the first line to:

$item.Fields["My YesNo Field"].DefaultValue = "1"

should work.

I can confirm that the following code works in SOM:

SPList list = site.Lists["YesNo"];
list.Fields["My YesNo Field"].DefaultValue = "1";
list.Fields["My YesNo Field"].Update();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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