0

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_overwrite(true);
fileCreateInfo.set_url(filename);
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);

clientContext.load(this.newFile);

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?

1 Answer 1

2

After upload you can do it as

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

item.set_item('Username', value);
item.Update();
clientContext.ExecuteQuery...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.