---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# DocumentVersionService - Scoped, Global

# DocumentVersionService - Scoped, Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 minutes to read

The DocumentVersionService API provides a service for creating and deleting document versions. Each version is an element containing the document content and is provided using a single URL or attachment. An attachment can only be added in the Document Versions \[ds_document_version\] table UI and not with the API.

This API requires the Document Management
plugin (com.snc.platform_document_management) and is provided within the
`sn_doc_services` namespace. For information, see [Document Services](https://www.servicenow.com/docs/access?context=document-services-landing-page&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US).

Before creating a document version, you must first define and add a document record.

* [SystemDocument](https://servicenow-prod.fluidtopics.net/hiu62Cu~o3jKLyJ5uf3yhg#SystemDocumentBothAPI "The SystemDocument API provides methods for setting fields of a record in the Documents [ds_document] table.") -- Define a document object.
* [DocumentService](https://servicenow-prod.fluidtopics.net/CHqHZXeSYpjShUPRtBPrNA#DocumentServiceBothAPI "The DocumentService API provides methods for creating, deleting, and updating a document.") -- Add, update, or delete a document.
{#DocumentVersionServiceBothAPI__ul_qyt_tpr_wpb}

## DocumentVersionService - DocumentVersionService() {#ariaid-title2}

Instantiates a DocumentVersionService object.
{#DocVersSvc-DocumentVersionService__table_zw5_mcg_tpb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#DocVersSvc-DocumentVersionService__table_zw5_mcg_tpb}  
The following example shows how to instantiate a DocumentVersionService
object.

    var versionSvc = new sn_doc_services.DocumentVersionService();

## DocumentVersionService - createDocumentVersion(SystemDocumentVersion docVersion) {#ariaid-title3}

Creates a document version record in the Versions \[ds_document_version\]
table.
{#DocVersSvc-createDocumentVersion_O__table_w4z_2cg_tpb__entry__3}

| Name | Type | Description |
|-|-|-|
| docVersion | [SystemDocumentVersion](https://servicenow-prod.fluidtopics.net/gj847yfDVadabQAsWTsEcw#SystemDocumentVersionBothAPI "The SystemDocumentVersion API provides methods for setting the values of a document's source version in the Versions [ds_document_version] table.") | One or more properties representing fields of a document version. |
[Table 2. Parameters]

{#DocVersSvc-createDocumentVersion_O__table_w4z_2cg_tpb} {#DocVersSvc-createDocumentVersion_O__table_tj4_p5j_34b__entry__2}{#DocVersSvc-createDocumentVersion_O__row_pdfgen_ret_msgCnv}

| Type | Description |
|-|-|
| Object | Sys_id of the new record in the Versions \[ds_document_version\] table with a success message. Error message otherwise. { "message": "String", "request_id": "String", "status": "String" } |
| \<Object\>.message | Message confirming success or error. If successful, includes the sys_id of the document record and the sys_id of its new document version. Data type: String |
| \<Object\>.request_id | Sys_id of the new record in the Versions \[ds_document_version\] table. Data type: String |
| \<Object\>.status | Status indicating whether the operation is successful. Possible values: * success - The operation was successful. * failure -- The operation was not successful. The message provides details. {#DocVersSvc-createDocumentVersion_O__ul_rlv_5cv_j4b} Data type: String |
[Table 3. Returns]

{#DocVersSvc-createDocumentVersion_O__table_tj4_p5j_34b}  
The following example shows how to populate SystemDocumentVersion object
properties and create a new document version. See also [SystemDocumentVersion](https://servicenow-prod.fluidtopics.net/gj847yfDVadabQAsWTsEcw#SystemDocumentVersionBothAPI "The SystemDocumentVersion API provides methods for setting the values of a document's source version in the Versions [ds_document_version] table.").

    var versionDefinition = new sn_doc_services.SystemDocumentVersion('491efbee24187410f877a6fed1c2b0a9');

    versionDefinition.type('url');
    versionDefinition.url('http://one/1.0');

    var versionSvc = new sn_doc_services.DocumentVersionService();
    gs.info(JSON.stringify(versionSvc.createDocumentVersion(versionDefinition), null, 2));

Output:

    {
      "message": "Adding an entry to DocumentVersion for the given docId : 491efbee24187410f877a6fed1c2b0a9, sysId : d5a340d9242cf810f877a6fed1c2b069 is successful.",
      "request_id": "d5a340d9242cf810f877a6fed1c2b069",
      "status": "success"
    }

## DocumentVersionService - deleteDocumentVersion(String docVersionSysId) {#ariaid-title4}

Deletes a document version.
{#DocVersSvc-deleteDocumentVersion_S__table_w4z_2cg_tpb__entry__3}

| Name | Type | Description |
|-|-|-|
| docVersionSysId | String | Sys_id of a document version in the Versions \[ds_document_version\] table. |
[Table 4. Parameters]

{#DocVersSvc-deleteDocumentVersion_S__table_w4z_2cg_tpb} {#DocVersSvc-deleteDocumentVersion_S__table_x4z_2cg_tpb__entry__2}

| Type | Description |
|-|-|
| Object | Success message. Error message otherwise. { "message": "String", "status": "String" } {#DocVersSvc-deleteDocumentVersion_S__api_docserv_codeblock_dets} |
| \<Object\>.message | Message confirming success or error. If successful, includes the sys_id of the deleted document version. Data type: String |
| \<Object\>.status | Status indicating whether the operation is successful. Possible values: * success - The operation was successful. * failure -- The operation was not successful. The message provides details. {#DocVersSvc-deleteDocumentVersion_S__ul_rlv_5cv_j4b} Data type: String |
[Table 5. Returns]

{#DocVersSvc-deleteDocumentVersion_S__table_x4z_2cg_tpb}  
The following example shows how to delete an existing document version.

    var vId = "<versionSysId>";
    var versionSvc = new sn_doc_services.DocumentVersionService();

    gs.info(JSON.stringify(versionSvc.deleteDocumentVersion(vId), null, 2));

Output:

    {
      "message": "Deleting an entry to DocumentVersion for the given documentVersionSysId : , sysId : <versionSysId> is successful.",
      "status": "success"
    }


