making document id type of field auto populated

lhieanne
Tera Contributor

Hello everyone, I have a question regarding field auto-population in ServiceNow. I'm working with the task_time_worked table and looking to implement the following behavior:

  • Goal: Auto-populate a "Document ID"-type of field when creating a new record.

  • Trigger: When a user clicks the New button to add a time worked entry.

  • Expected Functionality:

    • The TABLE and NON TASK fields should be auto-fill, depending on the context or source record from which the user initiated the time entry for example in PRB table, or Vulnerable item table

Has anyone implemented a similar use case in ServiceNow? I’d appreciate any guidance on best practices, scripts (e.g., in a client script or UI policy), or configuration recommendations.

 

Below is the screenshot of the form in time worked.

 

lhieanne_0-1747294075080.png

 

1 REPLY 1

shantanu_patel8
Mega Guru

Hi @lhieanne ,

 

In order to populate these values you can use the following script in the business rule:

 

var tw = new GlideRecord('task_time_worked');

tw.initialize();

//other fields population

tw.u_target_table = current.getTableName();

tw.u_non_task = current.sys_id.toString();

//Other script lines. like tw.insert() or tw.update(); based on your requirement.

 

You can also refer to : https://www.servicenow.com/community/developer-forum/what-is-document-id-field-type-how-to-set-a-val...

 

Please mark the answer helpful and correct if it resolves the issue. Happy scripting 

shantanu_patel8_0-1747294883642.png

 

 

-Shantanu