Question

Albeit a newbie, I'm stumped that something this simple is causing an issue. I have a document in a document library in SPO that for which I'm trying to update 4 metadata attributes. Here is my syntax to populate the file ID:

const web = new Web(this.context.pageContext.web.absoluteUrl);

web.lists.getByTitle("Supplemental Filings").items.filter('PublicDisplay eq 1').expand("File").get().then(
      function(matchingFiles) {
        var fileNameSelector = document.getElementById("selFileName");

        for (var i = 0; i < matchingFiles.length; i++) {
          fileNameSelector.innerHTML += "<option value=\"" + matchingFiles[i].Id + "\">" + matchingFiles[i].File.Name + "</option>";
        }
    });

The event handler logic to update the selected file is where the error occurs:

var selectedUploadedFile: number;
selectedUploadedFile = parseInt((<HTMLSelectElement>document.getElementById("selFileName")).value);

web.lists.getByTitle("Supplemental Filings").items.getById(selectedUploadedFile).update(

{
    Case_x0020_Number: enteredCaseNumber,
    Attachment_Type: selectedAttachmentType,
    Brief_Description: enteredBriefDescription,
    PublicDisplay: 0
  }
).then(console.log).catch(console.error);

selectedUploadedFile contains the ID of the document (in this case 73). This produces the following error:

enter image description here

Running the following produces an array of documents which shows that the library can be queried successfully:

web.lists.getByTitle("Supplemental Filings").items.get().then(x => console.log(x));

I am unable to understand what the syntax error is frankly. Any insight is greatly appreciated.

Was it helpful?

Solution

Thanks Rune for getting me thinking the right direction. For Yes/No type fields the update has to be in the form of true/false:

web.lists.getByTitle("Supplemental Filings").items.getById(selectedUploadedFile).update(
        {
          Case_x0020_Number: enteredCaseNumber,
          Attachment_Type: selectedAttachmentType,
          Brief_Description: enteredBriefDescription,
          PublicDisplay: false
        }
).then(console.log).catch(console.error);
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top