Create new Library Item

Good Afternoon,

We have been utilising the pnp-js library to create and update items in other lists when required. We now have a requirement to create and update an item in a Document Library. Two questions/issues: -

Firstly the Create does not seem to work, the library is setup with a template word document for the default content type, but the code for the creation simply doesn’t do anything, I am thinking it is because the name of the document is a required field, but can’t see how I can set this. My basic code for this is below -

// Function to Create Word Document
function createWordDocument(reference) {
	debugger;
	var quoteTitle = fd.field('Quotation_x0020_Title').value;
	var list = pnp.sp.web.lists.getByTitle("Quotation%20Repository%202");
		list.items.add({
		Title: reference,
		QuotationTitle: quoteTitle
	}).then(function(){
	    console.log("Updated!");
	});
}

Secondly is there any error detection or success confirmation built in as there is a possibility that the Word Document could be open when the update is triggered in this instance we need to alert the user that the update did not work and reset fields accordingly. My update test code is below -

if (correspondenceAddressNameIdOnLoad != null && correspondenceAddressNameIdOnLoad != addressNameId) {
			var list = pnp.sp.web.lists.getByTitle("Quotation%20Repository%202");
			list.items.getById(12).update({
				CorrespondenceAddressLine1: correspondenceAddressLine1,
				CorrespondenceAddressLine2: correspondenceAddressLine2,
				CorrespondenceAddressLine3: correspondenceAddressLine3,
				CorrespondenceAddressTown: correspondenceAddressTownCity,
				CorrespondenceAddressCounty: correspondenceAddressCounty,
				CorrespondenceAddressPostCode: correspondenceAddressPostcode		
			}).then(function(){
			    console.log("Updated!");
			});
		}

Thanks in advance

Please ignore the second issue, I have resolved this using .catch

Could still do with a little help on the first one though.

Thanks

Dear Tony,

Please try the approach described in this article: https://github.com/pnp/pnpjs/issues/196