I have multiple document templates attached to a content type for a document library. Is there any way through designer workflows or jquery to get the document template url.

Below is the url for configuring the document templates for a document library.

http://sharepointchick.com/archive/2011/01/07/using-content-types-with-document-templates-when-using-quotnew-documentrdquo.aspx

  • Multiple templates attached to content type OR multiple content type attached to a document library? – Atish Dipongkor Oct 16 '15 at 16:51
  • Each template is attached to a content type. I.e if I have 3 content types which are in use for a document library. Each content type has a separate template – sandy143 Oct 18 '15 at 17:51
up vote 2 down vote accepted

Document template's URL can be found in the following end-point.

/_api/web/lists/GetByTitle('Your Library Name')/ContentTypes?$select=DocumentTemplate,DocumentTemplateUrl

You have to make a GET request in the above URL using jQuery.

function getTemplateUrl(libraryName) {
    var url = "/_api/web/lists/GetByTitle('" + libraryName + "')/ContentTypes?$select=DocumentTemplate,DocumentTemplateUrl"
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + url,
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
        },
        success: function(data) {
            console.log(data.d.results);
        },
        error: function(error) {
            alert(JSON.stringify(error));
        }
    });
}

Response will be like following

{
  "d": {
    "results": [
      {
        "__metadata": {
          "id": "https://yoursite.sharepoint.com/_api/Web/Lists(guid'63ff3aad-360b-4484-aade-283e603a975e')/ContentTypes('0x010100DA61ED65E37DE94084A585C06CB4F2D5')",
          "uri": "https://yoursite.sharepoint.com/_api/Web/Lists(guid'63ff3aad-360b-4484-aade-283e603a975e')/ContentTypes('0x010100DA61ED65E37DE94084A585C06CB4F2D5')",
          "type": "SP.ContentType"
        },
        "DocumentTemplate": "/Shared Documents/Forms/template.dotx",
        "DocumentTemplateUrl": "/Shared Documents/Forms/template.dotx"
      },
      {
        "__metadata": {
          "id": "https://yoursite.sharepoint.com/_api/Web/Lists(guid'63ff3aad-360b-4484-aade-283e603a975e')/ContentTypes('0x010100009856EF229E504FBF311FF61AB0E7000003FD588DCA1E6E4AB5A28B8441C27671')",
          "uri": "https://yoursite.sharepoint.com/_api/Web/Lists(guid'63ff3aad-360b-4484-aade-283e603a975e')/ContentTypes('0x010100009856EF229E504FBF311FF61AB0E7000003FD588DCA1E6E4AB5A28B8441C27671')",
          "type": "SP.ContentType"
        },
        "DocumentTemplate": "Excel Template.xlsx",
        "DocumentTemplateUrl": "/Shared Documents/Forms/Excel Content Type/Excel Template.xlsx"
      }
    ]
  }
}
  • This is exactly what I want. Awesome.... I will add it in my blog – sandy143 Oct 19 '15 at 18:09
  • Then share with me – Atish Dipongkor Oct 19 '15 at 18:13
  • but when I use this document url it updating the template. My scenario was to create a new document in to the document library using this template url.. Any idea why it behaving like that – sandy143 Oct 20 '15 at 15:59
  • I did not get your scenario. Please explain more – Atish Dipongkor Oct 20 '15 at 16:02
  • once we copy paste the url in a browser it open up the template. Now when I add some content and save the template it is not saving in the document library. where as it is updating the document template. It should as a new document in the document library right? – sandy143 Oct 20 '15 at 16:06

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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