Custom 'Created date' field capturing incorrect values.

sanvi
Tera Expert

Hi All,

I have a requirement to capture the 'Created' i.e sys_created_on values on a new field that captures only the created date and not the time stamp for reporting purpose, same with the updated and closed fields

So i have created a new Date field 'Created date' and configured a business rule to update this field value.

 

But this newly created date field is not capturing correct values, there is a difference of a day (lag) between created dates in custom field and OOB field.

Can anyone suggest. Below are the details.

 

Business Rule

Type - Before Insert

Script-

 

current.u_created = current.sys_created_on;
   //current.update();
 
Report-
 
sanvi_0-1744092477030.png

Thanks in advance.

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

@sanvi 

it's date type so your script is wrong as it's trying to set Date/time to Date field

use this if u_created is of Date type


var nowTime = new GlideDateTime();
var nowDate = nowTime.getDate();
current.setValue('u_created', nowDate);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar ,

Thanks for your response. How can i use this code for Updated and closed fields as well. u_updated and u_closed_date being the custom fields.

@sanvi 

for u_updated you will have to use before update business rule and have similar logic

for u_closed_date you can have before update business rule and condition as Ticket closes

Have similar script

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Thanks @Ankur Bawiskar ,

Will make the changes and test. Hope it works overcoming timezone issues.