You are currently viewing ServiceNow Document ID Field Demo

ServiceNow Document ID Field Demo

Field Overview

ServiceNow has amazing data holding capacity. You can find almost all types of fields to store the data and that could be any type of data. Have you considered referencing a table record to another table?

If you are thinking of a reference field, it can work and possibly attach one-to-one relationships, i.e., in an incident record, I can attach a change request record. But if I want to have the freedom to attach any record from any table, the reference field will fail here because I have to define the reference table well in advance.

This problem is now solved by the Document ID field, which provides an opportunity  To reference records from any table. However,  two fields need to work together—one to store the table reference and another to store the record reference.

Steps To Create Document ID Field Setup

  • Create 2 fields shown below in screenshot 1
  • Test Doc ID = Document ID Type, Reference Table = String (You can choose any names as per your choice
Screenshot 1
  • Now set the dependent value of the Test Doc ID (document ID type) field as Reference Table, as shown in screenshot 2
Screenshot 2
  • Now you can use the fields, provide the name of the table in the Reference table and click on the Test Doc ID field to select the record (Screenshot 3)
Screenshot 3

Difference between the Reference Field & Document ID Field?

Reference Field Document ID Field
Reference record from one tableReference record from any table
Need to define reference table in advance while field creationHave to specify reference table explicitly on form only

How to use Document ID in Script?

//Display in background script

var gr = new GlideRecord('incident');
gs.print(gr.u_test_doc_id); // document ID printing
*** Script: b0dbda5347c12200e0ef563dbb9a718f
It return sys_id of reference record

//Set the value at server side script
 = 'incident';
current.u_test_doc_id = SYS_ID;

Remember to set the vaue of both referene tble and document id field.