I need to add a new item in a document library using JSOM
. The document library also possesses custom columns.
I am able to upload file but unable to get proper method to add the custom column values to the library using JSOM.
Following is the code that I have used for updating:
function receivedBinary() {
clientContext = new SP.ClientContext.get_current();
parentList = clientContext.get_web().get_lists().getByTitle("Lib_MasterDataDetails");
fileCreateInfo = new SP.FileCreationInformation();
fileCreateInfo.set_url(file.name);
fileCreateInfo.set_overwrite(true);
fileCreateInfo.set_content(new SP.Base64EncodedByteArray());
var arr = convertDataURIToBinary(this.result);
for (var i = 0; i < arr.length; ++i) {
fileCreateInfo.get_content().append(arr[i]);
}
newFile = parentList.get_rootFolder().get_files().add(fileCreateInfo);
clientContext.load(newFile);
clientContext.executeQueryAsync(function (newFile) {
var myListItem = newFile.get_listItemAllFields();
myListItem.set_item("ClientLegalName", "NewValue");
myListItem.update();
clientContext.executeQueryAsync(function (sender, args) {
console.log("Item updated");
}, genericFailHandler);
}, genericFailHandler);
}