Can sys_id be retrieved before record is saved in a UI Action?

SHUNAKAMINE
Giga Contributor

Hi all,

I have a question about retrieving sys_id before a record is saved.

In a server-side UI Action, I am using code like this:

(function executeAction(current, previous) {
gs.info('UI ACTION START: sys_id=' + current.getUniqueValue());
})();

When this UI Action is executed before the record is saved (for example, on a new record form),
current.getUniqueValue() returns null / undefined.

My question is:
Is it expected behavior that sys_id cannot be retrieved before the record is saved,
even though attachments added before save appear to be stored in sys_attachment
with a table_sys_id value?

In other words:
• Does ServiceNow assign a real sys_id only at insert time?
• Are attachments added before saving associated with a temporary or placeholder sys_id?

I would appreciate clarification on how sys_id assignment works internally
and whether there is any supported way to reliably obtain a record's sys_id
before the first save.

1 REPLY 1

Tanushree Maiti
Kilo Patron

Hi @SHUNAKAMINE 

 

1. Yes. When using .insert()  ServiceNow generates the 32-character sys_id at the moment of insertion. Record is  not fully committed until .insert() is executed.

 

2. When a user uploads an attachment to a record producer before submitting, the attachment is created in the sys_attachment table. It is associated with a temporary table_sys_id .

 

3. While you can predict or generate a sys_id earlier using scripting methods like setNewGuid() the record does not exist in the database until the .insert() method is called.

Refer: insert record with given sys_id 

 

Still I will suggest you to go for automatic sys_id assignation. don't go using the script.

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: