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
  • 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" Mar 10, 2015 at 15:12

1 Answer 1

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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