Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, July 11, 2012 1:06 PM
I am trying to change / set the value of yes/no field in sharepoint.
this are the combinations that I have used:
item["ZIP_x0020_Code_x0020_Linked"] = 0;
item["ZIP_x0020_Code_x0020_Linked"] = false;
item["ZIP_x0020_Code_x0020_Linked"] = "No";
item["ZIP_x0020_Code_x0020_Linked"] = "false";
In every case I ge the following error, eventhough I used 0 and 1.
Invalid Yes/No value.
A Yes/No field contains invalid data. It should be either 1 or 0. Please check the value and try again.
any working code will be very much appreciated.
thank you
All replies (5)
Wednesday, July 11, 2012 1:24 PM ✅Answered
Hi,
There are several ways to do this.
item["ColumnName"] = 0;
item["ColumnName"] = $false;
I just tried this and it was working correctly. Here is what I did (for testing purposes):
$list = (Get-SPWeb "https://portal.contoso.com").Lists["Test"]
$items = $list.Items
$item = $items[0]
$item["YesNo"] = 1
$item.Update()
Are you able to retrieve the current value of "Zip Code Linked"?
Yo can see the current value by using
$item["ZIP_x0020_Code_x0020_Linked"]
Nico Martens - MCTS, MCITP
SharePoint 2010 Infrastructure Consultant / Trainer
Wednesday, July 11, 2012 1:18 PM
Totally guessing:
item["ZIP_x0020_Code_x0020_Linked"] = "0";
item["ZIP_x0020_Code_x0020_Linked"] = '0';
Steve Clark, MCTS | Twin-Soft.com & Easy Bins Dumpster Rentals of Northern VA. (Specializing in driveway-sized roll-off dumpsters.)
Wednesday, July 11, 2012 1:18 PM
Hi
If you use Yes/No field.
item["MyField"] = true;
item["MyField"] = false;
Above solution works for me.
You may try to assign the value to bool variable and then assign var instead of direct true/false.
Regards, Marcin (Please mark as helpful or answered if it helps)
Wednesday, July 11, 2012 1:26 PM
Not sure why setting the value to true or false does not work but the code should be
item["YesNoField"] = true;
or
item["YesNoField"] = false;
Amit
Friday, July 13, 2012 10:07 PM
Hi,
It appears in your example that you are using the internal name. you might just try to use the display name of your yes/no field and assign true/false value;
Let me know if this helps