2

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.

5
  • What are the field types of the four columns you are trying to update? – Rune Sperre Feb 27 '20 at 18:18
  • Hi Rune, Case #: Single line of text Attachment Type: Choice Brief Description: Multiple lines of text Public Display: Yes/No Thanks. – user6009780 Feb 27 '20 at 19:05
  • Did your change fix the problem? – Rune Sperre Feb 27 '20 at 19:32
  • 1
    Hi Rune - indeed the problem is resolved. Apparently just changing the Yes/No update to a True/False (instead of 0/1) was the change needed. Many thanks. – user6009780 Mar 2 '20 at 14:55
  • Great, you should accept your own answer so this question can be closed :) – Rune Sperre Mar 2 '20 at 15:24
1

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);

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.