I am creating custom webpart in SPFx. I have a yes/no column. I have to use PNP js to get the value, when that check box got selected.

That value I should save it in SharePoint column as Yes, if its unchecked it should be saved as No.

Can some one give me the code.

I tried with .prop("checked" "checked) and .attr("checked", true). Both are throwing error its not accepting in PNPjs.

Please assist me.



In REST, booleans (YesNo choice) fields should be set as 0/1 i.e 0 for No and 1 for yes.

So, you can use the below sample code. We will first check if the checkbox is checked. If it is checked, will set the value in our code to 1, if unchecked will set it to 0 and after that will add/update our list item. Please use the internal columns names for this making the REST queries :

var checkboxValue = $('#checkboxId').is(":checked") ? 1 : 0;

pnp.sp.web.lists.getByTitle("Custom List").items.add({
    Title: "Title",
    BoolField : checkboxValue
}).then((i: ItemAddResult) => {
  • any update on this @nagarajan ? If it helped you, you can accept this answer by ticking the checkmark besides the answer ! It will remove this question from list of unanswered questions, thanks :) – Gautam Sheth Sep 10 '18 at 9:05

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.