I am using JavaScript to upload a file in a document library, like this

clientContext = new SP.ClientContext.get_current();
oWebsite = clientContext.get_web();
oList = oWebsite.get_lists().getByTitle("The_List_Where_I_Upload");

fileCreateInfo = new SP.FileCreationInformation();
fileCreateInfo.set_content(content); /*the content is generated somewhere else, it's not important in this question*/

this.newFile = oList.get_rootFolder().get_files().add(fileCreateInfo);


The code works, but let's say, at the same time when I upload the file I also want to set the value of another column in the document library, for example Username or User Address.

I tried with `fileCreateInfo.set_item('Username', value); but it throws an error saying

set_item is not a function.

Is it possible to set other columns values while uploading a file to a document library?


After upload you can do it as

clientContext.load(this.newFile, 'ListItemAllFields');
var item = this.newFile.get_listItemAllFields();

item.set_item('Username', value);

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.