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.

Calculated Value of Field is Empty on Report

Ankit Singh4
Tera Contributor

Hi Experts,

 

I have created one custom field as Integer which stores only the hour of created field. 

Calculate code:

(function calculatedFieldValue(current) {

	var date1 = new GlideDateTime(current.getDisplayValue('sys_created_on'));
    var g_hours = date1.getTime();
    return g_hours.getByFormat('HH');// return the calculated value

})(current);

Above code is giving me required output. Now, the problem is when I use that field in report to show the hours it is giving me empty. And, when I refresh the incidents record it starts reflecting in the list. But, it is only giving me those records which has been refreshed.

Note: Refresh on record here I am doing is, I clicked on list view short description and without updating anything I saved it and it start giving me the records in reports.

 

Please suggest if I need to refresh records to show in reports for calculated field.

 

Thanks,

Ankit Singh
 

14 REPLIES 14

Hello @Ankit Singh4 

Try

glidefunction:getHours('sys_created_on').

 

The other workaround is to create custom field on table that holds current date and time and caluculate tye different using glidefunction:datediff(sys_updated_on, custom_field)

Like explained in the thread below:

https://www.servicenow.com/community/platform-analytics-forum/time-since-now-in-a-function-field-in-...

please mark the answer as helpful and correct based on Impact!!

 

Kind Regards,

Ravi Chandra.

Hi @Ravi Chandra_K,

 

It is not working as per requirement.

 

Thanks,

Ankit Singh

Samaksh Wani
Giga Sage

Hello @Ankit Singh4 

 

 

(function calculatedFieldValue(current) {

	var date1 = new GlideDateTime(current.getDisplayValue('sys_created_on'));
    var g_hours = date1.getTime();
    return g_hours.getHour();// return the calculated value

})(current);

 

 

 

You can use this script.

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Samaksh

 

Hi @Samaksh Wani

Thanks for your response!!

I already have used the same script.

Regards,

Ankit Singh

Hello @Ankit Singh4 

 

If your query got resolved, then Plz mark my response as Accept and close the thread. It will help future readers to reach the post.

 

Regards,

Samaksh