How to set a value to a document ID field using script

pdv
Kilo Contributor

Hi all,

I am trying to set the value of document ID type field using script.

I tried to assign the sys id directly but its not working.

can someone throw some light?

1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

A sys_id is useless without a knowing what table the record resides on.


Alas, a Document ID field needs to be coupled with a Table Name field.



First you will need to create a 'Table Name' field (let's say 'u_table').


Once you have done that,open the Dictionary entry of your Document ID field and set the dependent field to 'u_table'.


Then you can write the following code



current.u_table = 'incident';


current.u_doc_id = SYS_ID;


current.update();



Or set in via the UI, setting the u_table field first.



I hope this helps



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

4 REPLIES 4

The SN Nerd
Giga Sage
Giga Sage

A sys_id is useless without a knowing what table the record resides on.


Alas, a Document ID field needs to be coupled with a Table Name field.



First you will need to create a 'Table Name' field (let's say 'u_table').


Once you have done that,open the Dictionary entry of your Document ID field and set the dependent field to 'u_table'.


Then you can write the following code



current.u_table = 'incident';


current.u_doc_id = SYS_ID;


current.update();



Or set in via the UI, setting the u_table field first.



I hope this helps



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Mike Allen
Mega Sage

It needs a source table.   I did it in approval like this:



var appr = new GlideRecord('sysapproval_approver');


appr.initialize();


appr.source_table = 'change_request';


appr.sysapproval = 'a9e9c33dc61122760072455df62663d2';


appr.document_id = 'a9e9c33dc61122760072455df62663d2';


appr.insert();


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Dv,



You may find the below thread helpful.


Syntax for Glide Insert a field of Document ID Type


free
Kilo Contributor

if i want to map any value to doucment Id in transform map, then??