Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Populate the date and time to a field when record is submitted

Pat Surtan
Tera Expert

Hi,

I have a custom table with a field called Resolved_time. I want the field to show the date and time of the system just like the Updated field when the record is submitted. Also, I want the format to look like the Updated field. How do I populate the date and time into this custom field?

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Pat,

Create a before business rule and set the script as follows:

if (current.u_resolved_time.nil())  // 'u_resolve_time' is a name of the custom field in the custom table
    current.u_resolved_time = gs.nowDateTime();

Full steps.

1. In custom table, create field "Resolved Time" with name 'u_resolved_time" of type "Date/Time"

find_real_file.png

2. Create a Business Rule.

  1. From Application Navigator, go to "System Definition" > "Business Rules"
  2. Select custom table in "Table" field. Select "When to run" tab and set "When" to "before" and check "Insert" and "Update"
    find_real_file.png
  3. Check "Advanced" and select "Advanced" tab. Enter script and save.
    find_real_file.png

View solution in original post

3 REPLIES 3

Roger Poore
Tera Guru

Take a look at the Incident form and its Resolved field.  Also look at the business rule mark_resolved. That will show you how to do what you want.  

Rather than just tell you how to do it, I'd rather tell how to figure these things out. ServiceNow has a lot of OOB code that does most things developers would need to do.

 -Roger

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Pat,

Create a before business rule and set the script as follows:

if (current.u_resolved_time.nil())  // 'u_resolve_time' is a name of the custom field in the custom table
    current.u_resolved_time = gs.nowDateTime();

Full steps.

1. In custom table, create field "Resolved Time" with name 'u_resolved_time" of type "Date/Time"

find_real_file.png

2. Create a Business Rule.

  1. From Application Navigator, go to "System Definition" > "Business Rules"
  2. Select custom table in "Table" field. Select "When to run" tab and set "When" to "before" and check "Insert" and "Update"
    find_real_file.png
  3. Check "Advanced" and select "Advanced" tab. Enter script and save.
    find_real_file.png

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Can you explain the business requirement for that field?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader