Create New Document in directly in Library instead of just upload existing

Home Forums vLooup for SharePoint Create New Document in directly in Library instead of just upload existing

Viewing 3 reply threads
  • Author
    Posts
    • #33684
      Brian Oster
      Participant

        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.

      • #33686
        Brian Oster
        Participant

          I may have found another thread that may do what I want.

          Post #29668

          • #33688
            Alexander Bautz
            Keymaster

              Great, I’m glad you found the other post.

              Alexander

          • #33693
            Brian Oster
            Participant

              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 properties

              Here 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, 6 months ago by Brian Oster.
            • #33697
              Brian Oster
              Participant

                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();
                                }
                            }
                • #33699
                  Brian Oster
                  Participant

                    Never mind. Finally got it all working. Your example code from Post 29668 was all good. I had the Document Library GUID wrong.

                  • #33703
                    Alexander Bautz
                    Keymaster

                      I’m glad you figured it out!

                      Alexander

                Viewing 3 reply threads
                • You must be logged in to reply to this topic.