Home › Forums › vLooup for SharePoint › Create New Document in directly in Library instead of just upload existing
- This topic has 6 replies, 2 voices, and was last updated 3 years, 5 months ago by Alexander Bautz.
-
AuthorPosts
-
-
June 1, 2021 at 18:30 #33684
I have a vLookup for a document library and have configured a button to Add a new document which opens a dialog that prompts the user to upload an existing document from their computer. I display the documents in a Tab of the Parent item. This works great.
I would also like the ability to have a button (or some other method) that creates a new document directly in the library very similar to the default functionality in SharePoint for a doc lib when “New Document” is select from the files menu of the doc lib. Ultimately I would like to find a way to have multiple document templates for the library and allow the user to select “New Document” and then have some kind of drop down that would select among multiple templates.
-
June 1, 2021 at 20:32 #33686
I may have found another thread that may do what I want.
-
June 2, 2021 at 16:00 #33688
Great, I’m glad you found the other post.
Alexander
-
-
June 2, 2021 at 21:55 #33693
So very close. I have it creating documents from my Templates Doc Lib and inserting into the target Doc Lib but I can’t
a) get it to link to the parent
b) set additional propertiesHere is the relevant section of js:
` if (res.count > 0)
{
var item = res.items[0];
var uRes = spjs.utility.updateItem(
{
“listName”: targetLibGUID,
“id”: item.ID,
“data”:
{
“Project_x0020_ID”: getFieldValue(“ID”),
“Category”: “Special Instructions”
}
});See attachment for vLookup Query Definition. I even tried hard coding the Project ID value just to see if it would work and it still would not set that property.
- This reply was modified 3 years, 5 months ago by Brian Oster.
Attachments:
-
June 3, 2021 at 15:04 #33697
After debugging I found the initial problem. It appears it is not finding the inserted document object. The line “if(res.count > 0)” fails so it never trys to set the document properties. So spjs.utility.queryItems appears to not find the document.
var res = spjs.utility.queryItems({ "listName": targetLibGUID, "query": "<Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='Text'>" + newDocName + "</Value></Eq></Where>", "viewFields": ["ID", "EncodedAbsUrl"] }); debugger; if (res.count > 0) { var item = res.items[0]; var uRes = spjs.utility.updateItem({ "listName": targetLibGUID, "id": item.ID, "data": { "Project_x0020_ID": projectID, "Category": "Special Instructions" } }); if (uRes.success) { // Refresh vLookup table jQuery("#vLookupManualRefresh_" + vLookupFieldname).trigger("click"); var a = document.createElement("a"); a.setAttribute("href", "ms-word:ofe|u|" + item.EncodedAbsUrl); a.setAttribute("target", "_blank"); document.getElementsByTagName("body")[0].appendChild(a); a.click(); } }
-
June 3, 2021 at 15:22 #33699
Never mind. Finally got it all working. Your example code from Post 29668 was all good. I had the Document Library GUID wrong.
-
June 3, 2021 at 20:21 #33703
I’m glad you figured it out!
Alexander
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.