---
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


---

# DocumentService - Scoped, Global

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

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

The DocumentService API provides methods for creating, deleting, and updating a document.

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).

A document is a collection of information about a document record. The methods used to create
or update a record modify fields using the [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.") object.  
Document content is managed using versions. The following APIs enable you to define and manage document versions:

* [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.") -- Define a document version as the source of the document content. 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.
* [DocumentVersionService](https://servicenow-prod.fluidtopics.net/4rBv_OwF58wU1tUMi3qe3g#DocumentVersionServiceBothAPI "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.") -- Document content is managed using versions.
{#DocumentServiceBothAPI__ul_krc_vmf_vpb}

Use the [DocumentReferenceService](https://servicenow-prod.fluidtopics.net/XbCYlqgA9dNciIZ6E0uBew#DocumentReferenceServiceBothAPI "The DocumentReferenceService API provides methods for managing document references within a target table, such as the Incidents [incident] or Knowledge [kb_knowledge] table. You can use document references to associate information with a record.") API to manage documents referenced in a target table, such
as the Incidents \[incident\] or Knowledge \[kb_knowledge\] table.  
The Document Management plugin also supports creating lists of document templates to associate with your document. For example, a job application requiring multiple documents such as a diploma, ID, or passport.

* [SystemDocumentList](https://servicenow-prod.fluidtopics.net/rr3G17VMlKG_id40USYdIg#SystemDocumentListBothAPI "The SystemDocumentList API provides methods for setting the record fields in the Document Lists [ds_document_lists] table.") -- Define a list of document templates.
* [DocumentListService](https://servicenow-prod.fluidtopics.net/0dw9H_Qgi6UOWxUD~Znlew#DocumentListServiceBothAPI "The DocumentListService API provides methods for creating, deleting, and updating a document list.") -- Add or remove a document template list.
* [SystemDocumentListEntry](https://servicenow-prod.fluidtopics.net/dTZ4yFvdYi6QadMYeJbW4g#SystemDocumentListEntryBothAPI "The SystemDocumentListEntry API provides methods for setting the record fields in the Document List Entries [ds_document_list_entry] table.") -- Define a document template list entry.
* [DocumentListEntryService](https://servicenow-prod.fluidtopics.net/O8CQazRfDWbzjMyrnT1K~Q#DocumentListEntryServiceBothAPI "The DocumentListEntryService API provides methods for maintaining document templates in a document list.") -- Add or remove a document template list entry.
{#DocumentServiceBothAPI__ul_asn_gjg_vpb}

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

Instantiates a DocumentService object.
{#DocumentService-DocumentService__table_zw5_mcg_tpb__entry__3}

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

{#DocumentService-DocumentService__table_zw5_mcg_tpb}  
The following example shows how to instantiate a DocumentService
object.

    var s = new sn_doc_services.DocumentService();

## DocumentService - createDocument(SystemDocument doc) {#ariaid-title3}

Creates a document record in the Documents \[ds_document\] table.
{#DocumentService-createDocument_O__table_w4z_2cg_tpb__entry__3}

| Name | Type | Description |
|-|-|-|
| doc | [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.") | One or more properties representing fields of a new record. The name property is required and can be set using the SystemDocument constructor or name() method. |
[Table 2. Parameters]

{#DocumentService-createDocument_O__table_w4z_2cg_tpb} {#DocumentService-createDocument_O__table_tj4_p5j_34b__entry__2}{#DocumentService-createDocument_O__row_pdfgen_ret_msgCnv}

| Type | Description |
|-|-|
| Object | Sys_id of the new record in the Documents \[ds_document\] table with a success message. Error message otherwise. { "message": "String", "request_id": "String", "status": "String" } |
| \<Object\>.message | Message confirming success or error. Possible values: * Create document sysId : \<sys_id\> is successful. * Document Name is mandatory and should be valid. * Document Name is mandatory and it should not be null or empty. * \<[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.") property requiring sys_id input\> with SysId: "\<sys_id\>" does not exist {#DocumentService-createDocument_O__ul_hwn_lbh_tpb} Data type: String |
| \<Object\>.request_id | Sys_id of the record in the Documents \[ds_document\] 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. {#DocumentService-createDocument_O__ul_rlv_5cv_j4b} Data type: String |
[Table 3. Returns]

{#DocumentService-createDocument_O__table_tj4_p5j_34b}  
The following example shows how to populate SystemDocument object
properties and create a new document record.

    var d = new sn_doc_services.SystemDocument('My document');

    // Define the document fields
    var reviewers = '62826bf03710200044e0bfc8bcbe5df1,a8f98bb0eb32010045e1a5115206fe3a';
    d.description('description');
    d.classification('restricted');
    d.state('review');
    d.department('93b25282c0a8000b0b55c8ab34e2f1e6');
    d.template(false);
    d.type('policy');
    d.reviewers(reviewers);
    d.audience('external');

    var s = new sn_doc_services.DocumentService();
    gs.info(JSON.stringify(s.createDocument(d), null, 2));

Output:

    {
      "message": "Create document sysId : 1040420224503410f877a6fed1c2b031 is successful.",
      "request_id": "1040420224503410f877a6fed1c2b031",
      "status": "success"
    }

## DocumentService - deleteDocument(String docSysId) {#ariaid-title4}

Removes a document record from the Documents \[ds_document\] table.
{#DocumentService-deleteDocument_S__table_w4z_2cg_tpb__entry__3}{#DocumentService-deleteDocument_S__ph_docserv_parm_docID}

| Name | Type | Description |
|-|-|-|
| docSysId | String | Sys_id of a document record in the Documents \[ds_document\] table. |
[Table 4. Parameters]

{#DocumentService-deleteDocument_S__table_w4z_2cg_tpb} {#DocumentService-deleteDocument_S__table_x4z_2cg_tpb__entry__2}{#DocumentService-deleteDocument_S__ph-docserv-ret-obj-basic}

| Type | Description |
|-|-|
| Object | Success or error message. { "message": "String", "request_id": "String", "status": "String" } {#DocumentService-deleteDocument_S__api_docserv_codeblock_dets} |
| \<Object\>.message | Message confirming success or error. Data type: String |
| \<Object\>.request_id | Sys_id of the record in the Documents \[ds_document\] 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. {#DocumentService-deleteDocument_S__ul_rlv_5cv_j4b} Data type: String |
[Table 5. Returns]

{#DocumentService-deleteDocument_S__table_x4z_2cg_tpb}  
The following example shows how to delete an existing document record.

    var docid = "<sys_id>";
    var svc = new sn_doc_services.DocumentService();
    gs.info(JSON.stringify(svc.deleteDocument(docid), null, 2));

Output:

    {
      "message": "Delete document sysId : <sys_id> is successful.",
      "request_id": "<sys_id>",
      "status": "success"
    }

## DocumentService - updateDocument(String docSysId, SystemDocument doc) {#ariaid-title5}

Updates the field values of an existing document record.
{#DocumentService-updateDocument_S_O__table_w4z_2cg_tpb__entry__3}{#DocumentService-updateDocument_S_O__ph_docserv_parm_docID}

| Name | Type | Description |
|-|-|-|
| docSysId | String | Sys_id of a document record in the Documents \[ds_document\] table. |
| doc | [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.") | One or more properties representing document fields to be updated. |
[Table 6. Parameters]

{#DocumentService-updateDocument_S_O__table_w4z_2cg_tpb} {#DocumentService-updateDocument_S_O__table_x4z_2cg_tpb__entry__2}{#DocumentService-updateDocument_S_O__ph-docserv-ret-obj-basic}

| Type | Description |
|-|-|
| Object | Success or error message. { "message": "String", "request_id": "String", "status": "String" } {#DocumentService-updateDocument_S_O__api_docserv_codeblock_dets} |
| \<Object\>.message | Message confirming success or error. Data type: String |
| \<Object\>.request_id | Sys_id of the record in the Documents \[ds_document\] 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. {#DocumentService-updateDocument_S_O__ul_rlv_5cv_j4b} Data type: String |
[Table 7. Returns]

{#DocumentService-updateDocument_S_O__table_x4z_2cg_tpb}  
The following example shows how to change a document name. See also [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.").

    var dId = "19aab54e24103410f877a6fed1c2b03d";
    var d = new sn_doc_services.SystemDocument();
    d.name("c22.txt");

    var s = new sn_doc_services.DocumentService();
    gs.info(JSON.stringify(s.updateDocument(dId, d), null, 2));

Output:

    {
      "message": "Update document sysId : 19aab54e24103410f877a6fed1c2b03d is successful.",
      "request_id": "19aab54e24103410f877a6fed1c2b03d",
      "status": "success"
    }


